Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial release. Based on http://traviscline.com/blog/2010/04/27/usin…

  • Loading branch information...
commit efe27a1c817a6eba24a588d09a5f13920783e334 0 parents
@abourget authored
Showing with 130 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +44 −0 README.rst
  3. +85 −0 githg.py
1  .gitignore
@@ -0,0 +1 @@
+# Ingore Mercurial, until you need to inter-operate with it
44 README.rst
@@ -0,0 +1,44 @@
+git-hg bi-directional interface
+-------------------------------
+
+This does the job "hg-git" does for Mercurial, but the reverse. It actually uses
+the same tool (the gexport / gimport feature of Hg-Git), written by GitHub.
+
+This is based on the Blog post by Travis Cline
+
+ http://traviscline.com/blog/2010/04/27/using-hg-git-to-work-in-git-and-push-to-hg/
+
+To install:
+
+ sudo ln -s `pwd`/githg.py /usr/lib/git-core/git-hg
+
+Make sure you have hg-git installed. See http://hg-git.github.com/
+
+ git hg clone https://bitbucket.org/user/project
+
+Work on your Git repo, do some commits.
+
+ git hg push
+
+which pushes to the local .hg repo, and offers to push upstream.
+
+When new changes arrive from upstream, run:
+
+ git hg fetch
+
+or
+
+ git hg pull
+
+which map to the same Git semantics: ``fetch`` updates your branch with new stuff, and ``pull`` adds a merge to the mix.
+
+This code is not yet tested with complex topologies, additions, comments and pull requests are welcome.
+
+
+
+TODO
+----
+
+git-hg should check for a same bookmarks Hg configuration, etc.
+
+The first release was written at PyCon 2012, by Alexandre Bourget
85 githg.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+# -=- encoding: utf-8 -=-
+
+"""Git-hg is a bi-directional interface to Mercurial, like git-svn, but for Hg.
+
+ git hg clone hg://blah/repository
+ git hg push
+ git hg fetch
+ git hg pull
+
+
+Refs:
+ Isn't bi-directional: https://github.com/offbytwo/git-hg
+ Hard to remember: http://traviscline.com/blog/2010/04/27/using-hg-git-to-work-in-git-and-push-to-hg/
+
+"""
+
+import os
+import sys
+
+# TODO: when running a command, ensure the Hg bookmark plugin is active and
+# installed
+
+def clone(url):
+ """This makes an hg clone and makes that appear as a Git repository."""
+ subdir = os.path.basename(url)
+ os.system("hg clone -U %s" % (url,))
+ os.system("""
+cd %s
+hg bookmark hg/default -r default
+# Do the import
+hg gexport
+# Configure the git repo and checkout
+ln -s .hg/git .git
+git branch master hg/default
+git config core.bare false
+git reset --hard
+# Ignore the .hg stuff
+echo '.hg' >> .git/info/exclude
+echo "[ui]
+ignore = `pwd`/.hg/hgignore" >> .hg/hgrc
+echo ".git" >> .hg/hgignore
+""" % subdir)
+
+def push():
+ """Pushes back to the Hg repository.
+
+ Like ``git push``, but up to the remote Mercurial repo.
+
+ """
+ os.system("hg gimport")
+ res = raw_input("Import Git commits into Hg local repo. Push back to the Hg remote ?")
+ if res.lower() in ('y', 'yes', '1', 'true'):
+ os.system("hg push")
+ os.system("hg bookmark -f hg/default -r default")
+
+def fetch():
+ """Update the local branches with what is up on the remote Mercurial repo.
+
+ Equivalent to ``git fetch`` in Git.
+
+ This updates the Git branches to point to the Mercurial ones.
+
+ """
+ os.system("hg pull")
+ os.system("hg bookmark -f hg/default -r default")
+ os.system("hg gexport")
+
+def pull():
+ """Fetch and merge the remote changes to the Hg repo.
+
+ Equivalent to ``git pull`` in Git.
+
+ """
+ fetch()
+ os.system("git merge hg/default")
+
+
+if __name__ == '__main__':
+ map = {'clone': clone,
+ 'fetch': fetch,
+ 'pull': pull,
+ 'push': push}
+ if sys.argv[1] in map:
+ map[sys.argv[1]](*(sys.argv[2:]))
Please sign in to comment.
Something went wrong with that request. Please try again.