diff options
-rw-r--r-- | git/repo/base.py | 9 | ||||
-rw-r--r-- | git/repo/fun.py | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index a5bbaa64..a111d643 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -36,7 +36,8 @@ from fun import ( is_git_dir, find_git_dir, touch - ) + read_gitfile, + ) import os import sys @@ -52,7 +53,6 @@ __all__ = ('Repo', ) class Repo(object): - """Represents a git repository and allows you to query references, gather commit information, generate diffs, create and clone repositories query the log. @@ -117,6 +117,11 @@ class Repo(object): self.git_dir = gitpath self._working_tree_dir = curpath break + gitpath = read_gitfile(gitpath) + if gitpath: + self.git_dir = gitpath + self._working_tree_dir = curpath + break curpath, dummy = os.path.split(curpath) if not dummy: break diff --git a/git/repo/fun.py b/git/repo/fun.py index 9dfc00ea..f5abc27a 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -45,6 +45,17 @@ def find_git_dir(d): return find_git_dir(d) return None +def read_gitfile(f): + """ This is taken from the git setup.c:read_gitfile function. + :return gitdir path or None if gitfile is invalid.""" + + if not isfile(f): + return None + line = open(f, 'r').readline().rstrip() + if line[0:8] != 'gitdir: ': + return None + path = os.path.realpath(line[8:]) + return path if is_git_dir(path) else None def short_to_long(odb, hexsha): """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha |