summaryrefslogtreecommitdiff
path: root/git/refs/symbolic.py
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2017-06-26 14:54:28 -0400
committerSebastian Thiel <byronimo@gmail.com>2017-07-01 13:59:17 +0200
commitaec58a9d386d4199374139cd1fc466826ac3d2cf (patch)
tree81e24d83a4e95410fd63b986dc420f8d488fce66 /git/refs/symbolic.py
parent4bd708d41090fbe00acb41246eb22fa8b5632967 (diff)
downloadgitpython-aec58a9d386d4199374139cd1fc466826ac3d2cf.tar.gz
Repo: handle worktrees better
This makes Repo("foo") work when foo/.git is a file of the form created by "git worktree add", i.e. it's a text file that says: gitdir: /home/me/project/.git/worktrees/bar and where /home/me/project/.git/ is the nominal gitdir, but /home/me/project/.git/worktrees/bar has this worktree's HEAD etc and a "gitdir" file that contains the path of foo/.git . Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'git/refs/symbolic.py')
-rw-r--r--git/refs/symbolic.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 22b7c53e..90ecb62c 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -75,7 +75,12 @@ class SymbolicReference(object):
@classmethod
def _get_packed_refs_path(cls, repo):
- return osp.join(repo.git_dir, 'packed-refs')
+ try:
+ commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt').readlines()[0].strip()
+ except (OSError, IOError):
+ commondir = '.'
+ repodir = osp.join(repo.git_dir, commondir)
+ return osp.join(repodir, 'packed-refs')
@classmethod
def _iter_packed_refs(cls, repo):
@@ -122,13 +127,13 @@ class SymbolicReference(object):
# END recursive dereferencing
@classmethod
- def _get_ref_info(cls, repo, ref_path):
+ def _get_ref_info_helper(cls, repo, repodir, ref_path):
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
rela_path points to, or None. target_ref_path is the reference we
point to, or None"""
tokens = None
try:
- with open(osp.join(repo.git_dir, ref_path), 'rt') as fp:
+ with open(osp.join(repodir, ref_path), 'rt') as fp:
value = fp.read().rstrip()
# Don't only split on spaces, but on whitespace, which allows to parse lines like
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -159,6 +164,22 @@ class SymbolicReference(object):
raise ValueError("Failed to parse reference information from %r" % ref_path)
+ @classmethod
+ def _get_ref_info(cls, repo, ref_path):
+ """Return: (str(sha), str(target_ref_path)) if available, the sha the file at
+ rela_path points to, or None. target_ref_path is the reference we
+ point to, or None"""
+ try:
+ return cls._get_ref_info_helper(repo, repo.git_dir, ref_path)
+ except ValueError:
+ try:
+ commondir = open(osp.join(repo.git_dir, 'commondir'), 'rt').readlines()[0].strip()
+ except (OSError, IOError):
+ commondir = '.'
+
+ repodir = osp.join(repo.git_dir, commondir)
+ return cls._get_ref_info_helper(repo, repodir, ref_path)
+
def _get_object(self):
"""
:return: