Skip to content

Commit

Permalink
Trim trailing whitespace in .git file
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jul 1, 2019
1 parent a975b6d commit 0b9f733
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 62 deletions.
12 changes: 9 additions & 3 deletions src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs
Expand Up @@ -213,8 +213,9 @@ public void Submodules_Errors()
workingDir.CreateDirectory("sub6").CreateDirectory(".git");
workingDir.CreateDirectory("sub7").CreateFile(".git").WriteAllText("xyz");
workingDir.CreateDirectory("sub8").CreateFile(".git").WriteAllText("gitdir: \0<>");
workingDir.CreateDirectory("sub9").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub9");
workingDir.CreateDirectory("sub9").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub9\r\n");
workingDir.CreateDirectory("sub10").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub10");
workingDir.CreateDirectory("sub11").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub11 \t\v\r\n");

workingDir.CreateFile(".gitmodules").WriteAllText(@"
[submodule ""S1""] # whitespace-only path
Expand Down Expand Up @@ -260,13 +261,18 @@ public void Submodules_Errors()
[submodule ""S10""] # sub10/.git points to directory that has commondir directory (it should be a file)
path = sub10
url = http://github.com
[submodule ""S11""] # trailing whitespace in path
path = sub11
url = http://github.com
");
var repository = new GitRepository(GitEnvironment.Empty, GitConfig.Empty, gitDir.Path, gitDir.Path, workingDir.Path);

var submodules = repository.GetSubmodules();
AssertEx.Equal(new[]
{
"S10: 'sub10' 'http://github.com'",
"S11: 'sub11' 'http://github.com'",
"S9: 'sub9' 'http://github.com'"
}, submodules.Select(s => $"{s.Name}: '{s.WorkingDirectoryRelativePath}' '{s.Url}'"));

Expand All @@ -288,7 +294,7 @@ public void Submodules_Errors()
// The format of the file 'sub7\.git' is invalid.
string.Format(Resources.FormatOfFileIsInvalid, Path.Combine(workingDir.Path, "sub7", ".git")),
// Path specified in file 'sub8\.git' is invalid.
string.Format(Resources.PathSpecifiedInFileIsInvalid, Path.Combine(workingDir.Path, "sub8", ".git"))
string.Format(Resources.PathSpecifiedInFileIsInvalid, Path.Combine(workingDir.Path, "sub8", ".git"), "\0<>")
}, diagnostics);
}

Expand Down Expand Up @@ -363,7 +369,7 @@ public void GetSubmoduleHeadCommitSha()
var submoduleGitDir = temp.CreateDirectory();

var submoduleWorkingDir = workingDir.CreateDirectory("sub").CreateDirectory("abc");
submoduleWorkingDir.CreateFile(".git").WriteAllText("gitdir: " + submoduleGitDir.Path);
submoduleWorkingDir.CreateFile(".git").WriteAllText("gitdir: " + submoduleGitDir.Path + "\t \v\f\r\n\n\r");

var submoduleRefsHeadsDir = submoduleGitDir.CreateDirectory("refs").CreateDirectory("heads");
submoduleRefsHeadsDir.CreateFile("master").WriteAllText("0000000000000000000000000000000000000000");
Expand Down
9 changes: 4 additions & 5 deletions src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs
Expand Up @@ -174,7 +174,7 @@ internal static string GetWorkingDirectory(GitConfig config, string gitDirectory
// Path in gitdir file must be absolute.
if (!PathUtils.IsAbsolute(workingDirectory))
{
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsNotAbsolute, gitdirFilePath));
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsNotAbsolute, gitdirFilePath, workingDirectory));
}

try
Expand All @@ -183,7 +183,7 @@ internal static string GetWorkingDirectory(GitConfig config, string gitDirectory
}
catch
{
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, gitdirFilePath));
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, gitdirFilePath, workingDirectory));
}
}

Expand Down Expand Up @@ -533,8 +533,7 @@ private static string ReadDotGitFile(string path)
throw new InvalidDataException(string.Format(Resources.FormatOfFileIsInvalid, path));
}

// git does not trim whitespace:
var link = content.Substring(GitDirPrefix.Length);
var link = content.Substring(GitDirPrefix.Length).TrimEnd(CharUtils.AsciiWhitespace);

try
{
Expand All @@ -543,7 +542,7 @@ private static string ReadDotGitFile(string path)
}
catch
{
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, path));
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, path, link));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Build.Tasks.Git/Resources.resx
Expand Up @@ -130,10 +130,10 @@
<value>Unsupported repository version {0}. Only versions up to {1} are supported.</value>
</data>
<data name="PathSpecifiedInFileIsNotAbsolute" xml:space="preserve">
<value>Path specified in file '{0}' is not absolute.</value>
<value>Path specified in file '{0}' is not absolute: '{1}'.</value>
</data>
<data name="PathSpecifiedInFileIsInvalid" xml:space="preserve">
<value>Path specified in file '{0}' is invalid.</value>
<value>Path specified in file '{0}' is invalid: '{1}'</value>
</data>
<data name="ValueOfIsNotValidPath" xml:space="preserve">
<value>The value of {0} is not a valid path: '{1}'.</value>
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.cs.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.de.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.es.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.fr.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.it.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.ja.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.ko.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.pl.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.pt-BR.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.ru.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.tr.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.zh-Hans.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.zh-Hant.xlf
Expand Up @@ -63,13 +63,13 @@
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsInvalid">
<source>Path specified in file '{0}' is invalid.</source>
<target state="new">Path specified in file '{0}' is invalid.</target>
<source>Path specified in file '{0}' is invalid: '{1}'</source>
<target state="new">Path specified in file '{0}' is invalid: '{1}'</target>
<note />
</trans-unit>
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
<source>Path specified in file '{0}' is not absolute.</source>
<target state="new">Path specified in file '{0}' is not absolute.</target>
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="RecursionDetectedWhileResolvingReference">
Expand Down

0 comments on commit 0b9f733

Please sign in to comment.