From 75264789c04bbdaffd479ab7725c85b1b8876d8e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 21 Feb 2020 18:55:07 -0500 Subject: [PATCH] project: fix worktree init under Windows Git likes to create .git files with read-only permissions which makes it difficult to open+truncate+write in situ under Windows. Delete it before we write the file content to workaround. Change-Id: I3effd96525f0dfe0b90e298b6bf0b856ea26aa03 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256412 Tested-by: Mike Frysinger Reviewed-by: David Pursehouse --- project.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project.py b/project.py index d83dd2d7..b3b5d5cb 100644 --- a/project.py +++ b/project.py @@ -3034,6 +3034,9 @@ class Project(object): setting = fp.read() assert setting.startswith('gitdir:') 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 to avoid. + platform_utils.remove(dotgit) # Use relative path from checkout->worktree. with open(dotgit, 'w') as fp: print('gitdir:', os.path.relpath(git_worktree_path, self.worktree),