Skip to content

Commit 53b65e0

Browse files
committed
Added support for separeted git dir.
1 parent 0b820e6 commit 53b65e0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎git/repo/base.py

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from fun import (
3333
rev_parse,
3434
is_git_dir,
35+
read_gitfile,
3536
touch
3637
)
3738

@@ -113,6 +114,11 @@ def __init__(self, path=None, odbt = DefaultDBType):
113114
self.git_dir = gitpath
114115
self._working_tree_dir = curpath
115116
break
117+
gitpath = read_gitfile(gitpath)
118+
if gitpath:
119+
self.git_dir = gitpath
120+
self._working_tree_dir = curpath
121+
break
116122
curpath, dummy = os.path.split(curpath)
117123
if not dummy:
118124
break

‎git/repo/fun.py

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ def is_git_dir(d):
3030
os.readlink(headref).startswith('refs'))
3131
return False
3232

33+
def read_gitfile(f):
34+
""" This is taken from the git setup.c:read_gitfile function.
35+
:return gitdir path or None if gitfile is invalid."""
36+
37+
if not isfile(f):
38+
return None
39+
line = open(f, 'r').readline().rstrip()
40+
if line[0:8] != 'gitdir: ':
41+
return None
42+
path = os.path.realpath(line[8:])
43+
return path if is_git_dir(path) else None
3344

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

0 commit comments

Comments
 (0)