@@ -3375,24 +3375,29 @@ def _InitGitWorktree(self):
3375
3375
setting = fp .read ()
3376
3376
assert setting .startswith ("gitdir:" )
3377
3377
git_worktree_path = setting .split (":" , 1 )[1 ].strip ()
3378
- # Some platforms (e.g. Windows) won't let us update dotgit in situ
3379
- # because of file permissions. Delete it and recreate it from scratch
3380
- # to avoid.
3381
- platform_utils .remove (dotgit )
3382
- # Use relative path from checkout->worktree & maintain Unix line endings
3383
- # on all OS's to match git behavior.
3384
- with open (dotgit , "w" , newline = "\n " ) as fp :
3385
- print (
3386
- "gitdir:" ,
3387
- os .path .relpath (git_worktree_path , self .worktree ),
3388
- file = fp ,
3389
- )
3390
- # Use relative path from worktree->checkout & maintain Unix line endings
3391
- # on all OS's to match git behavior.
3392
- with open (
3393
- os .path .join (git_worktree_path , "gitdir" ), "w" , newline = "\n "
3394
- ) as fp :
3395
- print (os .path .relpath (dotgit , git_worktree_path ), file = fp )
3378
+
3379
+ # `gitdir` maybe be either relative or absolute depending on the
3380
+ # behavior of the local copy of git, so only convert the path to
3381
+ # relative if it needs to be converted.
3382
+ if os .path .isabs (git_worktree_path ):
3383
+ # Some platforms (e.g. Windows) won't let us update dotgit in situ
3384
+ # because of file permissions. Delete it and recreate it from
3385
+ # scratch to avoid.
3386
+ platform_utils .remove (dotgit )
3387
+ # Use relative path from checkout->worktree & maintain Unix line
3388
+ # endings on all OS's to match git behavior.
3389
+ with open (dotgit , "w" , newline = "\n " ) as fp :
3390
+ print (
3391
+ "gitdir:" ,
3392
+ os .path .relpath (git_worktree_path , self .worktree ),
3393
+ file = fp ,
3394
+ )
3395
+ # Use relative path from worktree->checkout & maintain Unix line
3396
+ # endings on all OS's to match git behavior.
3397
+ with open (
3398
+ os .path .join (git_worktree_path , "gitdir" ), "w" , newline = "\n "
3399
+ ) as fp :
3400
+ print (os .path .relpath (dotgit , git_worktree_path ), file = fp )
3396
3401
3397
3402
self ._InitMRef ()
3398
3403
0 commit comments