Always use Unix EOL for worktree .git and gitdir files

Worktree .git and gitdir reference files are written by Git with
Unix line ending, even on Windows & macOS. The conversion to
relative paths makes these files end with DOS line endings in
Windows.  The Git integration in Visual Studio 2019 cannot deal
with these DOS line endings and considers these worktrees invalid.

Signed-off-by: Remy Bohmer <github@bohmer.net>
Change-Id: I088cfd994f3cc31db4e0ca7791fa0a4ee3ac222f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/289310
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Remy Bohmer <linux@bohmer.net>
This commit is contained in:
Remy Bohmer 2020-11-20 21:19:10 +01:00 committed by Mike Frysinger
parent d7f8683daf
commit 44bc9643ed

View File

@ -2702,12 +2702,14 @@ class Project(object):
# Some platforms (e.g. Windows) won't let us update dotgit in situ because # 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. # of file permissions. Delete it and recreate it from scratch to avoid.
platform_utils.remove(dotgit) platform_utils.remove(dotgit)
# Use relative path from checkout->worktree. # Use relative path from checkout->worktree & maintain Unix line endings
with open(dotgit, 'w') as fp: # on all OS's to match git behavior.
with open(dotgit, 'w', newline='\n') as fp:
print('gitdir:', os.path.relpath(git_worktree_path, self.worktree), print('gitdir:', os.path.relpath(git_worktree_path, self.worktree),
file=fp) file=fp)
# Use relative path from worktree->checkout. # Use relative path from worktree->checkout & maintain Unix line endings
with open(os.path.join(git_worktree_path, 'gitdir'), 'w') as fp: # 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) print(os.path.relpath(dotgit, git_worktree_path), file=fp)
self._InitMRef() self._InitMRef()