diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2014-04-27 12:55:38 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2014-04-27 12:55:38 +0200 |
commit | 673b21e1be26b89c9a4e8be35d521e0a43a9bfa1 (patch) | |
tree | 39815087c80e1bc48e8f236bdd200536b880f5ea /git | |
parent | 811a6514571a94ed2e2704fb3a398218c739c9e9 (diff) | |
parent | ec0b85e2d4907fb5fcfc5724e0e8df59e752c0d1 (diff) | |
download | gitpython-673b21e1be26b89c9a4e8be35d521e0a43a9bfa1.tar.gz |
Merge pull request #156 from remram44/fix-git-in-submodule
Fixes creating a Repo for a submodule (#155)
Diffstat (limited to 'git')
-rw-r--r-- | git/repo/base.py | 7 | ||||
-rw-r--r-- | git/repo/fun.py | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index 3bbcdb59..9ac471a6 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -32,6 +32,7 @@ from gitdb.util import ( from fun import ( rev_parse, is_git_dir, + find_git_dir, touch ) @@ -108,8 +109,8 @@ class Repo(object): self.git_dir = curpath self._working_tree_dir = os.path.dirname(curpath) break - gitpath = join(curpath, '.git') - if is_git_dir(gitpath): + gitpath = find_git_dir(join(curpath, '.git')) + if gitpath is not None: self.git_dir = gitpath self._working_tree_dir = curpath break @@ -119,7 +120,7 @@ class Repo(object): # END while curpath if self.git_dir is None: - raise InvalidGitRepositoryError(epath) + raise InvalidGitRepositoryError(epath) self._bare = False try: diff --git a/git/repo/fun.py b/git/repo/fun.py index 7a8657ab..2c49d836 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -7,6 +7,7 @@ from gitdb.util import ( join, isdir, isfile, + dirname, hex_to_bin, bin_to_hex ) @@ -31,6 +32,18 @@ def is_git_dir(d): return False +def find_git_dir(d): + if is_git_dir(d): + return d + elif isfile(d): + with open(d) as fp: + content = fp.read().rstrip() + if content.startswith('gitdir: '): + d = join(dirname(d), content[8:]) + return find_git_dir(d) + return None + + def short_to_long(odb, hexsha): """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha or None if no candidate could be found. |