Skip to content

Commit

Permalink
Trim trailing whitespace in .git file (#312)
Browse files Browse the repository at this point in the history
* Trim trailing whitespace in .git file

* Fix strings
  • Loading branch information
tmat committed Jul 1, 2019
1 parent 229d459 commit 51310e6
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 251 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
18 changes: 9 additions & 9 deletions src/Microsoft.Build.Tasks.Git/Resources.resx
Expand Up @@ -118,10 +118,10 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="PathMustBeAbsolute" xml:space="preserve">
<value>Path must be absolute</value>
<value>Path must be absolute.</value>
</data>
<data name="PathMustBeFilePath" xml:space="preserve">
<value>Path must be a file path</value>
<value>Path must be a file path.</value>
</data>
<data name="ErrorReadingGitRepositoryInformation" xml:space="preserve">
<value>Error reading git repository information: {0}</value>
Expand All @@ -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 All @@ -160,16 +160,16 @@
<value>Configuration file recursion exceeded maximum allowed depth of {0}.</value>
</data>
<data name="SubmoduleWithoutCommit" xml:space="preserve">
<value>Submodule '{0}' doesn't have any commit</value>
<value>Submodule '{0}' doesn't have any commit.</value>
</data>
<data name="InvalidSubmoduleUrl" xml:space="preserve">
<value>The URL of submodule '{0}' is missing or invalid: '{1}'</value>
<value>The URL of submodule '{0}' is missing or invalid: '{1}'.</value>
</data>
<data name="InvalidSubmodulePath" xml:space="preserve">
<value>The path of submodule '{0}' is missing or invalid: '{1}'</value>
<value>The path of submodule '{0}' is missing or invalid: '{1}'.</value>
</data>
<data name="SourceCodeWontBeAvailableViaSourceLink" xml:space="preserve">
<value>{0} -- the source code won't be available via Source Link.</value>
<value>{0} The source code won't be available via Source Link.</value>
</data>
<data name="RepositoryHasNoCommit" xml:space="preserve">
<value>Repository has no commit.</value>
Expand All @@ -190,6 +190,6 @@
<value>The value of {0} is not a valid configuration scope: '{1}'.</value>
</data>
<data name="HomeRelativePathsAreNotAllowed" xml:space="preserve">
<value>Home relative paths are not allowed when {0} is '{1}': '{2}'</value>
<value>Home relative paths are not allowed when {0} is '{1}': '{2}'.</value>
</data>
</root>
36 changes: 18 additions & 18 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.cs.xlf
Expand Up @@ -18,8 +18,8 @@
<note />
</trans-unit>
<trans-unit id="HomeRelativePathsAreNotAllowed">
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'</source>
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'</target>
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'.</source>
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidFormatOfFileAtPath">
Expand All @@ -43,33 +43,33 @@
<note />
</trans-unit>
<trans-unit id="InvalidSubmodulePath">
<source>The path of submodule '{0}' is missing or invalid: '{1}'</source>
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'</target>
<source>The path of submodule '{0}' is missing or invalid: '{1}'.</source>
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidSubmoduleUrl">
<source>The URL of submodule '{0}' is missing or invalid: '{1}'</source>
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'</target>
<source>The URL of submodule '{0}' is missing or invalid: '{1}'.</source>
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="PathMustBeAbsolute">
<source>Path must be absolute</source>
<target state="new">Path must be absolute</target>
<source>Path must be absolute.</source>
<target state="new">Path must be absolute.</target>
<note />
</trans-unit>
<trans-unit id="PathMustBeFilePath">
<source>Path must be a file path</source>
<target state="new">Path must be a file path</target>
<source>Path must be a file path.</source>
<target state="new">Path must be a file path.</target>
<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 Expand Up @@ -98,13 +98,13 @@
<note />
</trans-unit>
<trans-unit id="SourceCodeWontBeAvailableViaSourceLink">
<source>{0} -- the source code won't be available via Source Link.</source>
<target state="new">{0} -- the source code won't be available via Source Link.</target>
<source>{0} The source code won't be available via Source Link.</source>
<target state="new">{0} The source code won't be available via Source Link.</target>
<note />
</trans-unit>
<trans-unit id="SubmoduleWithoutCommit">
<source>Submodule '{0}' doesn't have any commit</source>
<target state="new">Submodule '{0}' doesn't have any commit</target>
<source>Submodule '{0}' doesn't have any commit.</source>
<target state="new">Submodule '{0}' doesn't have any commit.</target>
<note />
</trans-unit>
<trans-unit id="UnableToLocateRepository">
Expand Down
36 changes: 18 additions & 18 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.de.xlf
Expand Up @@ -18,8 +18,8 @@
<note />
</trans-unit>
<trans-unit id="HomeRelativePathsAreNotAllowed">
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'</source>
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'</target>
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'.</source>
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidFormatOfFileAtPath">
Expand All @@ -43,33 +43,33 @@
<note />
</trans-unit>
<trans-unit id="InvalidSubmodulePath">
<source>The path of submodule '{0}' is missing or invalid: '{1}'</source>
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'</target>
<source>The path of submodule '{0}' is missing or invalid: '{1}'.</source>
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidSubmoduleUrl">
<source>The URL of submodule '{0}' is missing or invalid: '{1}'</source>
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'</target>
<source>The URL of submodule '{0}' is missing or invalid: '{1}'.</source>
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="PathMustBeAbsolute">
<source>Path must be absolute</source>
<target state="new">Path must be absolute</target>
<source>Path must be absolute.</source>
<target state="new">Path must be absolute.</target>
<note />
</trans-unit>
<trans-unit id="PathMustBeFilePath">
<source>Path must be a file path</source>
<target state="new">Path must be a file path</target>
<source>Path must be a file path.</source>
<target state="new">Path must be a file path.</target>
<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 Expand Up @@ -98,13 +98,13 @@
<note />
</trans-unit>
<trans-unit id="SourceCodeWontBeAvailableViaSourceLink">
<source>{0} -- the source code won't be available via Source Link.</source>
<target state="new">{0} -- the source code won't be available via Source Link.</target>
<source>{0} The source code won't be available via Source Link.</source>
<target state="new">{0} The source code won't be available via Source Link.</target>
<note />
</trans-unit>
<trans-unit id="SubmoduleWithoutCommit">
<source>Submodule '{0}' doesn't have any commit</source>
<target state="new">Submodule '{0}' doesn't have any commit</target>
<source>Submodule '{0}' doesn't have any commit.</source>
<target state="new">Submodule '{0}' doesn't have any commit.</target>
<note />
</trans-unit>
<trans-unit id="UnableToLocateRepository">
Expand Down
36 changes: 18 additions & 18 deletions src/Microsoft.Build.Tasks.Git/xlf/Resources.es.xlf
Expand Up @@ -18,8 +18,8 @@
<note />
</trans-unit>
<trans-unit id="HomeRelativePathsAreNotAllowed">
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'</source>
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'</target>
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'.</source>
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidFormatOfFileAtPath">
Expand All @@ -43,33 +43,33 @@
<note />
</trans-unit>
<trans-unit id="InvalidSubmodulePath">
<source>The path of submodule '{0}' is missing or invalid: '{1}'</source>
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'</target>
<source>The path of submodule '{0}' is missing or invalid: '{1}'.</source>
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="InvalidSubmoduleUrl">
<source>The URL of submodule '{0}' is missing or invalid: '{1}'</source>
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'</target>
<source>The URL of submodule '{0}' is missing or invalid: '{1}'.</source>
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="PathMustBeAbsolute">
<source>Path must be absolute</source>
<target state="new">Path must be absolute</target>
<source>Path must be absolute.</source>
<target state="new">Path must be absolute.</target>
<note />
</trans-unit>
<trans-unit id="PathMustBeFilePath">
<source>Path must be a file path</source>
<target state="new">Path must be a file path</target>
<source>Path must be a file path.</source>
<target state="new">Path must be a file path.</target>
<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 Expand Up @@ -98,13 +98,13 @@
<note />
</trans-unit>
<trans-unit id="SourceCodeWontBeAvailableViaSourceLink">
<source>{0} -- the source code won't be available via Source Link.</source>
<target state="new">{0} -- the source code won't be available via Source Link.</target>
<source>{0} The source code won't be available via Source Link.</source>
<target state="new">{0} The source code won't be available via Source Link.</target>
<note />
</trans-unit>
<trans-unit id="SubmoduleWithoutCommit">
<source>Submodule '{0}' doesn't have any commit</source>
<target state="new">Submodule '{0}' doesn't have any commit</target>
<source>Submodule '{0}' doesn't have any commit.</source>
<target state="new">Submodule '{0}' doesn't have any commit.</target>
<note />
</trans-unit>
<trans-unit id="UnableToLocateRepository">
Expand Down

0 comments on commit 51310e6

Please sign in to comment.