@@ -1094,7 +1094,7 @@ def test_is_valid_object(self):
10941094 self .assertFalse (repo .is_valid_object (tag_sha , "commit" ))
10951095
10961096 @with_rw_directory
1097- def test_git_work_tree_dotgit (self , rw_dir ):
1097+ def test_git_work_tree_dotgit (self , rw_dir , use_relative_paths = False ):
10981098 """Check that we find .git as a worktree file and find the worktree
10991099 based on it."""
11001100 git = Git (rw_dir )
@@ -1106,7 +1106,11 @@ def test_git_work_tree_dotgit(self, rw_dir):
11061106 worktree_path = join_path_native (rw_dir , "worktree_repo" )
11071107 if Git .is_cygwin ():
11081108 worktree_path = cygpath (worktree_path )
1109- rw_master .git .worktree ("add" , worktree_path , branch .name )
1109+ wt_add_kwargs = {"insert_kwargs_after" : "add" }
1110+ # relative worktree paths introduced in git 2.48.0
1111+ if use_relative_paths and git .version_info [:3 ] >= (2 , 48 , 0 ):
1112+ wt_add_kwargs ["relative_paths" ] = True
1113+ rw_master .git .worktree ("add" , worktree_path , branch .name , ** wt_add_kwargs )
11101114
11111115 # This ensures that we can read the repo's gitdir correctly.
11121116 repo = Repo (worktree_path )
@@ -1124,6 +1128,15 @@ def test_git_work_tree_dotgit(self, rw_dir):
11241128
11251129 self .assertIsInstance (repo .heads ["aaaaaaaa" ], Head )
11261130
1131+ def test_git_work_tree_dotgit_relative (self ):
1132+ """Check that we find .git as a worktree file containing a relative path
1133+ and find the worktree based on it."""
1134+ if Git ().version_info [:3 ] < (2 , 48 , 0 ):
1135+ pytest .skip ("relative worktree feature unsupported, needs git 2.48.0 or later" )
1136+ # this class inherits from TestCase so we can't use pytest.mark.parametrize on
1137+ # test_git_work_tree_dotgit; delegate instead
1138+ self .test_git_work_tree_dotgit (use_relative_paths = True )
1139+
11271140 @with_rw_directory
11281141 def test_git_work_tree_env (self , rw_dir ):
11291142 """Check that we yield to GIT_WORK_TREE."""
0 commit comments