From a07855ad105430cb341355a2513ade72a368b33a Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Sun, 8 Sep 2019 15:47:42 -0700 Subject: [PATCH] Trim trailing whitespace when readong commondir --- .../GitRepositoryTests.cs | 6 +++--- .../GitDataReader/GitRepository.cs | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs b/src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs index 2c8f378d..2bf7add7 100644 --- a/src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs +++ b/src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs @@ -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( diff --git a/src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs b/src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs index 9cbceddc..f1ec1d4d 100644 --- a/src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs +++ b/src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs @@ -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 {