diff options
author | Peter Jones <pjones@redhat.com> | 2017-06-26 14:54:28 -0400 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2017-07-01 13:59:17 +0200 |
commit | aec58a9d386d4199374139cd1fc466826ac3d2cf (patch) | |
tree | 81e24d83a4e95410fd63b986dc420f8d488fce66 /git/repo/base.py | |
parent | 4bd708d41090fbe00acb41246eb22fa8b5632967 (diff) | |
download | gitpython-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/repo/base.py')
-rw-r--r-- | git/repo/base.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index 2f67a341..28bb2a5d 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -32,7 +32,7 @@ from git.remote import Remote, add_progress, to_progress_instance from git.util import Actor, finalize_process, decygpath, hex_to_bin import os.path as osp -from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch +from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch, find_worktree_git_dir import gc import gitdb @@ -138,10 +138,15 @@ class Repo(object): self._working_tree_dir = os.getenv('GIT_WORK_TREE', os.path.dirname(self.git_dir)) break - sm_gitpath = find_submodule_git_dir(osp.join(curpath, '.git')) + dotgit = osp.join(curpath, '.git') + sm_gitpath = find_submodule_git_dir(dotgit) if sm_gitpath is not None: self.git_dir = osp.normpath(sm_gitpath) - sm_gitpath = find_submodule_git_dir(osp.join(curpath, '.git')) + + sm_gitpath = find_submodule_git_dir(dotgit) + if sm_gitpath is None: + sm_gitpath = find_worktree_git_dir(dotgit) + if sm_gitpath is not None: self.git_dir = _expand_path(sm_gitpath) self._working_tree_dir = curpath |