diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2014-11-19 11:20:14 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2014-11-19 11:20:14 +0100 |
commit | d48ed95cc7bd2ad0ac36593bb2440f24f675eb59 (patch) | |
tree | 62cc11be743350b13f85cc8945233ece21c60610 | |
parent | 6fc9e6150957ff5e011142ec5e9f8522168602ec (diff) | |
parent | 706d3a28b6fa2d7ff90bbc564a53f4007321534f (diff) | |
download | gitpython-d48ed95cc7bd2ad0ac36593bb2440f24f675eb59.tar.gz |
Merge branch 'niyaton-separate-git-dir' into 0.3
-rw-r--r-- | git/repo/base.py | 11 | ||||
-rw-r--r-- | git/repo/fun.py | 18 |
2 files changed, 25 insertions, 4 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index a5bbaa64..5273d4b2 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -35,8 +35,9 @@ from fun import ( rev_parse, is_git_dir, find_git_dir, - touch - ) + read_gitfile, + touch, + ) 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(curpath) + 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..0bff677a 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -13,7 +13,8 @@ from gitdb.util import ( ) from string import digits -__all__ = ('rev_parse', 'is_git_dir', 'touch') +__all__ = ('rev_parse', 'is_git_dir', 'touch', 'read_gitfile', 'find_git_dir', 'name_to_object', + 'short_to_long', 'deref_tag', 'to_commit') def touch(filename): @@ -45,6 +46,21 @@ 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 f is None: + return None + try: + line = open(f, 'r').readline().rstrip() + except (OSError, IOError): + # File might not exist or is unreadable - ignore + return None + # end handle file access + 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 |