I cloned a private Git repository to C:\REDACTED\http and ran a build. The LocateRepository task in Microsoft.Build.Tasks.Git 1.0.0 created a SourceRoot item with the correct directory path C:\REDACTED\http\:
Task "Microsoft.Build.Tasks.Git.LocateRepository"
Task Parameter:Path=C:\REDACTED\http\REDACTED
Output Property: _GitRepositoryId=C:\REDACTED\http\.git
Output Property: ScmRepositoryUrl=REDACTED
Output Item(s):
SourceRoot=
C:\REDACTED\http\
RevisionId=REDACTED
ScmRepositoryUrl=REDACTED
SourceControl=git
Output Property: SourceRevisionId=REDACTED
Done executing task "Microsoft.Build.Tasks.Git.LocateRepository".
Set Property: RepositoryType=git
Then, I created another worktree for the same repository: git worktree add ../apu
And ran a build in C:\REDACTED\apu. This time, the LocateRepository task created a SourceRoot item with the incorrect directory path C:\REDACTED\apu\.git\. The correct path would have been C:\REDACTED\apu\.
Task "Microsoft.Build.Tasks.Git.LocateRepository"
Task Parameter:Path=C:\REDACTED\apu\REDACTED
Output Property: _GitRepositoryId=C:\REDACTED\http\.git\worktrees\apu
Output Property: ScmRepositoryUrl=REDACTED
Output Item(s):
SourceRoot=
C:\REDACTED\apu\.git\
RevisionId=REDACTED
ScmRepositoryUrl=REDACTED
SourceControl=git
Output Property: SourceRevisionId=REDACTED
Done executing task "Microsoft.Build.Tasks.Git.LocateRepository".
Set Property: RepositoryType=git
C:\REDACTED\apu\.git is a file that contains gitdir: C:/REDACTED/http/.git/worktrees/apu.
C:\REDACTED\http\.git\worktrees\apu\gitdir is a file that contains C:/REDACTED/apu/.git.
The bug seems to be that GitRepository.GitWorkingDirectory expects the gitdir file to contain only the path of the worktree, without the trailing /.git:
|
workingDirectory = File.ReadAllText(gitdirFilePath); |
According to the gitrepository-layout documentation though, .git is expected there.
I cloned a private Git repository to
C:\REDACTED\httpand ran a build. The LocateRepository task in Microsoft.Build.Tasks.Git 1.0.0 created a SourceRoot item with the correct directory pathC:\REDACTED\http\:Then, I created another worktree for the same repository:
git worktree add ../apuAnd ran a build in
C:\REDACTED\apu. This time, the LocateRepository task created a SourceRoot item with the incorrect directory pathC:\REDACTED\apu\.git\. The correct path would have beenC:\REDACTED\apu\.C:\REDACTED\apu\.gitis a file that containsgitdir: C:/REDACTED/http/.git/worktrees/apu.C:\REDACTED\http\.git\worktrees\apu\gitdiris a file that containsC:/REDACTED/apu/.git.The bug seems to be that GitRepository.GitWorkingDirectory expects the
gitdirfile to contain only the path of the worktree, without the trailing/.git:sourcelink/src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs
Line 147 in 31c76ae
According to the gitrepository-layout documentation though,
.gitis expected there.