{"thread":{"id":"16181","subject":"bidirectional hg <-> git syncing","startedAt":"2008-11-05T12:48:37Z","lastAt":"2008-11-05T12:48:37Z","messageCount":1,"participants":["Ondrej Certik"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"94970","messageId":"85b5c3130811050448s28f2a26by266f9d674ecdacfd@mail.gmail.com","threadId":"16181","inReplyTo":null,"subject":"bidirectional hg <-> git syncing","fromName":"Ondrej Certik","fromEmail":"ondrej@certik.cz","sentAt":"2008-11-05T12:48:37Z","receivedAt":"2008-11-05T12:48:37Z","isPatch":false,"sender":{"key":"ondrej@certik.cz","avatar":"https://gravatar.com/avatar/106d05822138a98292e09d1580dbe8f27e05faecd87f13d5d58d889d0687771c?d=mp&s=160"},"body":"Hi,\n\nI wanted to share how we sync hg and git repo and I am interested if\nanyone has any comments to it.\n\nIn our project [0], we used Mercurial, but recently several of the\ncore developers including me switched to git, but because we already\nwrote docs and taught our users to use mercurial (see for example\n[1]), we want to support both. So currently our main repo is still\nmercurial and we automatically convert to git using\n\nOur /home/hg/repos/sympy/.hg/hgrc contains:\n\n[hooks]\n#update the git repo\nchangegroup = /home/git/update-sympy.sh\n\nwhere /home/git/update-sympy.sh is:\n\n-----------\n#!/bin/bash\n\ncd /home/git/repos/sympy\nsudo /bin/su git -c \"../fast-export/hg-fast-export.sh -r /home/hg/repos/sympy\"\ncd /home/git/repos/\nsudo /bin/su git -c \"rm -rf sympy.git\"\nsudo /bin/su git -c \"git clone --bare sympy/.git/ sympy.git\"\nsudo /bin/su git -c \"echo 'main SymPy repository' > sympy.git/description\"\nsudo /bin/su git -c \"touch sympy.git/git-daemon-export-ok\"\n---------\n\n\nWhich uses hg-fast-export to update the git repo.\n\n\nBefore pushing any patches in, we need to convert them to mercurial.\nSo if the user uses mercurial, nothing changes. If the user (like me)\nuses git, I need to convert the patches to mercurial first, so that I\ncan push it in. So I do the following sequence, starting off my master\nbranch:\n\ngit checkout -b fix\n# do some commits\n./hgconvert\n\nwhere the ./hgconvert script is:\n\n-----\n#! /bin/bash\n\nwork=`mktemp -t -d sym.XXX`\ngit format-patch -k -p -o $work master..HEAD\n# add a new line after the subject line so that Mercurial imports it fine.\nsed -i '4a\\\\' $work/*\ncd ~/repos/sympy.hg/\nhg import $work/*\nrm -r $work\n---------\n\nThis takes all patches commited after the master and commits them to\nmy hg repo at ~/repos/sympy.hg/. I'll then push them in, both our hg\nand git repo updates and then I do in my local git repository:\n\ngit checkout master\ngit pull   # this pulls the changes, essentially the same as in the\n\"fix\" branch, only from our official git repo\ngit branch -D fix\n\n\nThis works nicely as long as I do not do any merges in my local git\nrepo. Is there some way to also convert the branches and merges? As I\nunderstood it, there are tools that only convert the whole repo, but\nsince we already convert the whole repo from hg to git, I need to only\nconvert the latest commits from git back to hg.\n\nOne solution is to fully switch to git and convert to hg automatically\non our server -- and that's what we'll do soon probably. Then we'll be\nable to push nonlinear history in git, but only linear in mercurial.\n\nThanks,\nOndrej\n\n[0] http://code.google.com/p/sympy/\n[1] http://docs.sympy.org/sympy-patches-tutorial.html\n\nOndrej\n"}]}