Get this repo https://github.com/mnauw/git-remote-hg which is a fork
of the original and supports modern git/hg. Copy git-hg-helper
and git-remote-hg
to ~/bin
and make them executable with chmod +x ~/bin/git*
git clone hg::https://foss.heptapod.net/pypy/cffi cffi-git
hg clone https://foss.heptapod.net/pypy/cffi cffi-hg
Find out how many commits there are (assume the last commit was to default
)
export top=$(cd cffi-hg; hg id -r default -n)
Then prepare the file. The idea is:
- get the hg hash for the commit
$(cd ../cffi-hg; hg log -r $i -T"{node}\n")
- convert it to a git hash
$(cd cffi-git; git-hg-helper git-rev ...
- echo that without a newline
echo -n ...
- next, echo a space and then the hg branch for the commit
for (( i=0; i<=$top; i++)); do echo -n $(cd cffi-git; git-hg-helper git-rev $(cd ../cffi-hg; hg log -r $i -T"{node}\n")); echo " $(cd cffi-hg; hg log -r $i -T'{branch}\n')"; done >> hash-branch.txt
Iterate through the file, calling git checkout -q <hash> && git notes --ref refs/notes/branch add -m branch:<branch>
(cd cffi-git; $(awk -F" " '{print "git checkout -q " $1 " git notes --ref refs/notes/branch add -m branch:"$2}' hash-branch.txt))
I couldn't get git push --all
to work, it only pushed the local head. So I needed to push each branch separately.
- create a file of all the branches:
$(cd cffi-hg; hg branches | cut -f1 -d" " > branches.txt)
- for each branch, check it out and then push to the remote
while read branch; do git checkout branches/$branch && git push origin branches/$branch; done < branches.txt