Skip to content

Commit

Permalink
Trim trailing whitespace when reading commondir (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored Sep 8, 2019
1 parent 2a1e308 commit ed7cafd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public void LocateRepository_Worktree()
var worktreeGitSubDir = worktreeGitDir.CreateDirectory("B");
var worktreeDir = temp.CreateDirectory();
var worktreeSubDir = worktreeDir.CreateDirectory("C");
var worktreeGitFile = worktreeDir.CreateFile(".git").WriteAllText("gitdir: " + worktreeGitDir);
var worktreeGitFile = worktreeDir.CreateFile(".git").WriteAllText("gitdir: " + worktreeGitDir + " \r\n\t\v");

worktreeGitDir.CreateFile("HEAD");
worktreeGitDir.CreateFile("commondir").WriteAllText(mainGitDir.Path);
worktreeGitDir.CreateFile("gitdir").WriteAllText(worktreeGitFile.Path);
worktreeGitDir.CreateFile("commondir").WriteAllText(mainGitDir.Path + " \r\n\t\v");
worktreeGitDir.CreateFile("gitdir").WriteAllText(worktreeGitFile.Path + " \r\n\t\v");

// start under main repository directory:
Assert.True(GitRepository.LocateRepository(
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ private static bool IsGitDirectory(string directory, out string commonDirectory)
{
try
{
// note: git does not trim whitespace
commonDirectory = Path.Combine(directory, File.ReadAllText(commonLinkPath));
commonDirectory = Path.Combine(directory, File.ReadAllText(commonLinkPath).TrimEnd(CharUtils.AsciiWhitespace));
}
catch
{
Expand Down

0 comments on commit ed7cafd

Please sign in to comment.