summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorAllen Webb <allenwebb@google.com>2024-10-29 13:24:05 -0500
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-10-30 17:03:57 +0000
commit1d5098617ec7f476b76d1aa676e2a001d2c3d533 (patch)
treee2a590479ad74856fbfedf6aff9feed5a02e6d94 /project.py
parente219c78fe595c09c5d5b7023ae59f465a61f46ff (diff)
downloadgit-repo-1d5098617ec7f476b76d1aa676e2a001d2c3d533.tar.gz
worktree: Do not try to fix relative pathsv2.49.1
--worktree was broken with incorrect paths in the .git files whenever the local copy of git populated gitdir with relative paths instead of absoulte paths. Bug: 376251410 Change-Id: Id32dc1576315218967de2a9bfe43bf7a5a0e7aa6 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/440801 Commit-Queue: Allen Webb <allenwebb@google.com> Reviewed-by: Josip Sokcevic <sokcevic@google.com> Tested-by: Allen Webb <allenwebb@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/project.py b/project.py
index 50daa82f..9a7681e0 100644
--- a/project.py
+++ b/project.py
@@ -3375,24 +3375,29 @@ class Project:
3375 setting = fp.read() 3375 setting = fp.read()
3376 assert setting.startswith("gitdir:") 3376 assert setting.startswith("gitdir:")
3377 git_worktree_path = setting.split(":", 1)[1].strip() 3377 git_worktree_path = setting.split(":", 1)[1].strip()
3378 # Some platforms (e.g. Windows) won't let us update dotgit in situ 3378
3379 # because of file permissions. Delete it and recreate it from scratch 3379 # `gitdir` maybe be either relative or absolute depending on the
3380 # to avoid. 3380 # behavior of the local copy of git, so only convert the path to
3381 platform_utils.remove(dotgit) 3381 # relative if it needs to be converted.
3382 # Use relative path from checkout->worktree & maintain Unix line endings 3382 if os.path.isabs(git_worktree_path):
3383 # on all OS's to match git behavior. 3383 # Some platforms (e.g. Windows) won't let us update dotgit in situ
3384 with open(dotgit, "w", newline="\n") as fp: 3384 # because of file permissions. Delete it and recreate it from
3385 print( 3385 # scratch to avoid.
3386 "gitdir:", 3386 platform_utils.remove(dotgit)
3387 os.path.relpath(git_worktree_path, self.worktree), 3387 # Use relative path from checkout->worktree & maintain Unix line
3388 file=fp, 3388 # endings on all OS's to match git behavior.
3389 ) 3389 with open(dotgit, "w", newline="\n") as fp:
3390 # Use relative path from worktree->checkout & maintain Unix line endings 3390 print(
3391 # on all OS's to match git behavior. 3391 "gitdir:",
3392 with open( 3392 os.path.relpath(git_worktree_path, self.worktree),
3393 os.path.join(git_worktree_path, "gitdir"), "w", newline="\n" 3393 file=fp,
3394 ) as fp: 3394 )
3395 print(os.path.relpath(dotgit, git_worktree_path), file=fp) 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 self._InitMRef() 3402 self._InitMRef()
3398 3403