Skip to content

Added support for separeted git dir. #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from fun import (
rev_parse,
is_git_dir,
read_gitfile,
touch
)

Expand Down Expand Up @@ -113,6 +114,11 @@ def __init__(self, path=None, odbt = DefaultDBType):
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
Expand Down
11 changes: 11 additions & 0 deletions git/repo/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def is_git_dir(d):
os.readlink(headref).startswith('refs'))
return False

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
Expand Down