mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
worktree: Do not try to fix relative paths
--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>
This commit is contained in:
parent
e219c78fe5
commit
1d5098617e
41
project.py
41
project.py
@ -3375,24 +3375,29 @@ class Project:
|
|||||||
setting = fp.read()
|
setting = fp.read()
|
||||||
assert setting.startswith("gitdir:")
|
assert setting.startswith("gitdir:")
|
||||||
git_worktree_path = setting.split(":", 1)[1].strip()
|
git_worktree_path = setting.split(":", 1)[1].strip()
|
||||||
# Some platforms (e.g. Windows) won't let us update dotgit in situ
|
|
||||||
# because of file permissions. Delete it and recreate it from scratch
|
# `gitdir` maybe be either relative or absolute depending on the
|
||||||
# to avoid.
|
# behavior of the local copy of git, so only convert the path to
|
||||||
platform_utils.remove(dotgit)
|
# relative if it needs to be converted.
|
||||||
# Use relative path from checkout->worktree & maintain Unix line endings
|
if os.path.isabs(git_worktree_path):
|
||||||
# on all OS's to match git behavior.
|
# Some platforms (e.g. Windows) won't let us update dotgit in situ
|
||||||
with open(dotgit, "w", newline="\n") as fp:
|
# because of file permissions. Delete it and recreate it from
|
||||||
print(
|
# scratch to avoid.
|
||||||
"gitdir:",
|
platform_utils.remove(dotgit)
|
||||||
os.path.relpath(git_worktree_path, self.worktree),
|
# Use relative path from checkout->worktree & maintain Unix line
|
||||||
file=fp,
|
# endings on all OS's to match git behavior.
|
||||||
)
|
with open(dotgit, "w", newline="\n") as fp:
|
||||||
# Use relative path from worktree->checkout & maintain Unix line endings
|
print(
|
||||||
# on all OS's to match git behavior.
|
"gitdir:",
|
||||||
with open(
|
os.path.relpath(git_worktree_path, self.worktree),
|
||||||
os.path.join(git_worktree_path, "gitdir"), "w", newline="\n"
|
file=fp,
|
||||||
) as fp:
|
)
|
||||||
print(os.path.relpath(dotgit, git_worktree_path), file=fp)
|
# Use relative path from worktree->checkout & maintain Unix line
|
||||||
|
# endings on all OS's to match git behavior.
|
||||||
|
with open(
|
||||||
|
os.path.join(git_worktree_path, "gitdir"), "w", newline="\n"
|
||||||
|
) as fp:
|
||||||
|
print(os.path.relpath(dotgit, git_worktree_path), file=fp)
|
||||||
|
|
||||||
self._InitMRef()
|
self._InitMRef()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user