Mercurial > hg > hg-git
changeset 936:f7d0175264ce
paths: refactor gitdir detection to a function
Refactors the logic that decides if a local directory is a git directory into a
separate function. This will let us use it later on to integrate with
Mercurial's new paths component.
author | Durham Goode <durham@fb.com> |
---|---|
date | Mon, 24 Aug 2015 19:30:44 -0700 |
parents | 674f799afb04 |
children | f05962b0e78a |
files | hggit/__init__.py |
diffstat | 1 files changed, 19 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/hggit/__init__.py +++ b/hggit/__init__.py @@ -42,6 +42,7 @@ from mercurial import revset from mercurial import scmutil from mercurial import templatekw +from mercurial import ui as hgui from mercurial import util as hgutil from mercurial.node import hex from mercurial.i18n import _ @@ -91,16 +92,26 @@ def localpath(self): return self.p +def _isgitdir(path): + """True if the given file path is a git repo.""" + if os.path.exists(os.path.join(path, '.hg')): + return False + + if os.path.exists(os.path.join(path, '.git')): + # is full git repo + return True + + if (os.path.exists(os.path.join(path, 'HEAD')) and + os.path.exists(os.path.join(path, 'objects')) and + os.path.exists(os.path.join(path, 'refs'))): + # is bare git repo + return True + + return False + def _local(path): p = urlcls(path).localpath() - if (os.path.exists(os.path.join(p, '.git')) and - not os.path.exists(os.path.join(p, '.hg'))): - return gitrepo - # detect a bare repository - if (os.path.exists(os.path.join(p, 'HEAD')) and - os.path.exists(os.path.join(p, 'objects')) and - os.path.exists(os.path.join(p, 'refs')) and - not os.path.exists(os.path.join(p, '.hg'))): + if _isgitdir(p): return gitrepo # detect git ssh urls (which mercurial thinks is a file-like path) if util.isgitsshuri(p):