changeset 60:05a96f7750ad

add support for `hg clone git://github.com/defunkt/facebox.git`
author Chris Wanstrath <chris@ozmm.org>
date Wed, 29 Apr 2009 00:54:13 -0700
parents 19d714ee9941
children 65c961d0d232
files __init__.py gitrepo.py
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/__init__.py	Tue Apr 28 17:50:50 2009 -0700
+++ b/__init__.py	Wed Apr 29 00:54:13 2009 -0700
@@ -26,6 +26,10 @@
 import dulwich
 from git_handler import GitHandler
 
+# support for `hg clone git://github.com/defunkt/facebox.git`
+import gitrepo
+hg.schemes['git'] = gitrepo
+
 def gclone(ui, git_url, hg_repo_path=None):
     # determine new repo name
     if not hg_repo_path:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gitrepo.py	Wed Apr 29 00:54:13 2009 -0700
@@ -0,0 +1,27 @@
+from mercurial import hg, repo
+from git_handler import GitHandler
+
+class gitrepo(repo.repository):
+    capabilities = []
+
+    def __init__(self, ui, path, create=1):
+        dest = hg.defaultdest(path)
+
+        if dest.endswith('.git'):
+            dest = dest[:-4]
+
+        # create the local hg repo on disk
+        dest_repo = hg.repository(ui, dest, create=True)
+
+        # fetch the initial git data
+        git = GitHandler(dest_repo, ui)
+        git.remote_add('origin', path)
+        git.fetch('origin')
+
+        # checkout the tip
+        node = git.remote_head('origin')
+        hg.update(dest_repo, node)
+
+        raise SystemExit
+
+instance = gitrepo