I maintain Python Koans on mirrored on both Github using git and Bitbucket using mercurial. I get pull requests from both repos but it turns out keeping the two repos in sync is pretty easy. Here is how it's done...
Assuming I’m starting again on a clean laptop, first I clone both repos
~/git $ hg clone https://bitbucket.org/gregmalcolm/python_koans
~/git $ git clone
[email protected]:gregmalcolm/python_koans.git python_koans2
The only thing that makes a folder a git or mercurial repository is the .hg folder in the root of python_koans and the .git folder in the root of python_koans2. So I just need to move the .git folder over into the python_koans folder I'm using for mercurial:
~/git $ rm -rf python_koans/.git
~/git $ mv python_koans2/.git python_koans
~/git $ ls -la python_koans
total 48
drwxr-xr-x 11 greg staff 374 Mar 17 15:10 .
drwxr-xr-x 62 greg staff 2108 Mar 17 14:58 ..
drwxr-xr-x 12 greg staff 408 Mar 17 14:58 .git
-rw-r--r-- 1 greg staff 34 Mar 17 14:54 .gitignore
drwxr-xr-x 13 greg staff 442 Mar 17 14:54 .hg
-rw-r--r-- 1 greg staff 48 Mar 17 14:54 .hgignore
-rw-r--r-- 1 greg staff 365 Mar 17 14:54 Contributor Notes.txt
-rw-r--r-- 1 greg staff 1082 Mar 17 14:54 MIT-LICENSE
-rw-r--r-- 1 greg staff 5765 Mar 17 14:54 README.txt
drwxr-xr-x 10 greg staff 340 Mar 17 14:54 python 2
drwxr-xr-x 10 greg staff 340 Mar 17 14:54 python 3
That’s about it! Now git and mercurial are tracking files in the same folder. Of course you will still need to set up your .gitignore to ignore mercurial’s dotfiles and .hgignore to ignore git’s dotfiles or there will be squabbling in the backseat.
~/git $ cd python_koans/
~/git/python_koans $ cat .gitignore
*.pyc
*.swp
.DS_Store
answers
.hg <-- Ignore mercurial
~/git/python_koans $ cat .hgignore
syntax: glob
*.pyc
*.swp
.DS_Store
answers
.git <-- Ignore git
Because both my mirrors are both identical as far as tracked files are concerned I won’t yet see anything if I check statuses at this point:
~/git/python_koans $ git status
# On branch
master
nothing to commit (working directory clean)
~/git/python_koans $ hg status
~/git/python_koans
But how about if I accept a pull request from the bitbucket (mercuial) site?
~/git/python_koans $ hg status
~/git/python_koans $ git status
# On branch
master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: python 2/koans/about_decorating_with_classes.py
# modified: python 2/koans/about_iteration.py
# modified: python 2/koans/about_with_statements.py
# modified: python 3/koans/about_decorating_with_classes.py
# modified: python 3/koans/about_iteration.py
# modified: python 3/koans/about_with_statements.py
Mercurial doesn’t have any changes to track right now, but git has changes. Commit and push them up to github and balance is restored to the force:
~/git/python_koans $ git commit -am "Merge from bitbucket mirror: 'gpiancastelli - Fix for issue #21 and some other tweaks'"
[master 79ca184] Merge from bitbucket mirror: 'gpiancastelli - Fix for issue #21 and some other tweaks'
6 files changed, 78 insertions(+), 63 deletions(-)
~/git/python_koans $ git push origin
master
Or just use hg-git?
The github developers have actually published a plugin for automatic mirroring:
http://hg-git.github.com
I haven’t used it because at the time I tried it a couple of years ago I was having problems getting all the parts to play nice with each other. Probably works fine now though..