changeset 220:211fa793d74f

support local git repositories (fixes issue 5 bb)
author Abderrahim Kitouni <a.kitouni@gmail.com>
date Thu, 23 Jul 2009 08:38:20 +0100
parents 89dcbfaca32b
children 4be68870dc44
files __init__.py tests/test-git-clone tests/test-git-clone.out
diffstat 3 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/__init__.py
+++ b/__init__.py
@@ -14,8 +14,12 @@
 
 '''
 
-from mercurial import commands, extensions, hg
+from mercurial import commands, extensions, hg, util
 from mercurial.i18n import _
+
+from dulwich.repo import Repo
+from dulwich.errors import NotGitRepository
+
 import gitrepo, hgrepo
 from git_handler import GitHandler
 
@@ -24,6 +28,18 @@
 hg.schemes['git'] = gitrepo
 hg.schemes['git+ssh'] = gitrepo
 
+_oldlocal = hg.schemes['file']
+
+def _local(path):
+    p = util.drop_scheme('file', path)
+    try:
+        Repo(p)
+        return gitrepo
+    except NotGitRepository:
+        return _oldlocal(path)
+
+hg.schemes['file'] = _local
+
 def reposetup(ui, repo):
     klass = hgrepo.generate_repo_subclass(repo.__class__)
     repo.__class__ = klass
--- a/tests/test-git-clone
+++ b/tests/test-git-clone
@@ -37,20 +37,11 @@
 git add beta
 commit -m 'add beta'
 
-# dulwich does not presently support local git repos, workaround
 cd ..
-git daemon --base-path="$(pwd)"\
- --listen=localhost\
- --export-all\
- --pid-file=gitdaemon.pid \
- --detach --reuseaddr
 
-hg clone git://localhost/gitrepo hgrepo
+hg clone gitrepo hgrepo
 cd hgrepo
 hg log --graph
 
 echo % we should have some bookmarks
 hg book
-
-cd ..
-kill `cat gitdaemon.pid`
--- a/tests/test-git-clone.out
+++ b/tests/test-git-clone.out
@@ -1,6 +1,6 @@
 Initialized empty Git repository in gitrepo/.git/
 
-fetching from : git://localhost/gitrepo
+fetching from : gitrepo
 importing Hg objects into Git
 Counting objects: 6, done.
 Compressing objects:  33% (1/3)   
Compressing objects:  66% (2/3)   
Compressing objects: 100% (3/3)   
Compressing objects: 100% (3/3), done.