Skip to content

Commit 22c4671

Browse files
committed
Merge branch 'separate-git-dir' of https://github.com/niyaton/GitPython into niyaton-separate-git-dir
Conflicts: git/repo/base.py
2 parents 6fc9e61 + 53b65e0 commit 22c4671

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

git/repo/base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
is_git_dir,
3737
find_git_dir,
3838
touch
39-
)
39+
read_gitfile,
40+
)
4041

4142
import os
4243
import sys
@@ -52,7 +53,6 @@
5253

5354

5455
class Repo(object):
55-
5656
"""Represents a git repository and allows you to query references,
5757
gather commit information, generate diffs, create and clone repositories query
5858
the log.
@@ -117,6 +117,11 @@ def __init__(self, path=None, odbt=DefaultDBType):
117117
self.git_dir = gitpath
118118
self._working_tree_dir = curpath
119119
break
120+
gitpath = read_gitfile(gitpath)
121+
if gitpath:
122+
self.git_dir = gitpath
123+
self._working_tree_dir = curpath
124+
break
120125
curpath, dummy = os.path.split(curpath)
121126
if not dummy:
122127
break

git/repo/fun.py

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def find_git_dir(d):
4545
return find_git_dir(d)
4646
return None
4747

48+
def read_gitfile(f):
49+
""" This is taken from the git setup.c:read_gitfile function.
50+
:return gitdir path or None if gitfile is invalid."""
51+
52+
if not isfile(f):
53+
return None
54+
line = open(f, 'r').readline().rstrip()
55+
if line[0:8] != 'gitdir: ':
56+
return None
57+
path = os.path.realpath(line[8:])
58+
return path if is_git_dir(path) else None
4859

4960
def short_to_long(odb, hexsha):
5061
""":return: long hexadecimal sha1 from the given less-than-40 byte hexsha

0 commit comments

Comments
 (0)