Skip to content
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
2 changes: 1 addition & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ def _call_process(

turns into::

git rev-list --max-count=10 --header=master
git rev-list --max-count=10 --header master

:return:
Same as :meth:`execute`. If no args are given, used :meth:`execute`'s
Expand Down
3 changes: 2 additions & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def __init__(
sm_gitpath = find_worktree_git_dir(dotgit)

if sm_gitpath is not None:
git_dir = expand_path(sm_gitpath, expand_vars)
# worktrees can use relative paths as of Git 2.48, so we join to curpath
git_dir = osp.normpath(osp.join(curpath, sm_gitpath))
self._working_tree_dir = curpath
break

Expand Down
17 changes: 15 additions & 2 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ def test_is_valid_object(self):
self.assertFalse(repo.is_valid_object(tag_sha, "commit"))

@with_rw_directory
def test_git_work_tree_dotgit(self, rw_dir):
def test_git_work_tree_dotgit(self, rw_dir, use_relative_paths=False):
"""Check that we find .git as a worktree file and find the worktree
based on it."""
git = Git(rw_dir)
Expand All @@ -1106,7 +1106,11 @@ def test_git_work_tree_dotgit(self, rw_dir):
worktree_path = join_path_native(rw_dir, "worktree_repo")
if Git.is_cygwin():
worktree_path = cygpath(worktree_path)
rw_master.git.worktree("add", worktree_path, branch.name)
wt_add_kwargs = {"insert_kwargs_after": "add"}
# relative worktree paths introduced in git 2.48.0
if use_relative_paths and git.version_info[:3] >= (2, 48, 0):
wt_add_kwargs["relative_paths"] = True
rw_master.git.worktree("add", worktree_path, branch.name, **wt_add_kwargs)

# This ensures that we can read the repo's gitdir correctly.
repo = Repo(worktree_path)
Expand All @@ -1124,6 +1128,15 @@ def test_git_work_tree_dotgit(self, rw_dir):

self.assertIsInstance(repo.heads["aaaaaaaa"], Head)

def test_git_work_tree_dotgit_relative(self):
"""Check that we find .git as a worktree file containing a relative path
and find the worktree based on it."""
if Git().version_info[:3] < (2, 48, 0):
pytest.skip("relative worktree feature unsupported, needs git 2.48.0 or later")
# this class inherits from TestCase so we can't use pytest.mark.parametrize on
# test_git_work_tree_dotgit; delegate instead
self.test_git_work_tree_dotgit(use_relative_paths=True)

@with_rw_directory
def test_git_work_tree_env(self, rw_dir):
"""Check that we yield to GIT_WORK_TREE."""
Expand Down
Loading