Skip to content

Commit 51310e6

Browse files
authored
Trim trailing whitespace in .git file (#312)
* Trim trailing whitespace in .git file * Fix strings
1 parent 229d459 commit 51310e6

16 files changed

+256
-251
lines changed

src/Microsoft.Build.Tasks.Git.UnitTests/GitRepositoryTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ public void Submodules_Errors()
213213
workingDir.CreateDirectory("sub6").CreateDirectory(".git");
214214
workingDir.CreateDirectory("sub7").CreateFile(".git").WriteAllText("xyz");
215215
workingDir.CreateDirectory("sub8").CreateFile(".git").WriteAllText("gitdir: \0<>");
216-
workingDir.CreateDirectory("sub9").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub9");
216+
workingDir.CreateDirectory("sub9").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub9\r\n");
217217
workingDir.CreateDirectory("sub10").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub10");
218+
workingDir.CreateDirectory("sub11").CreateFile(".git").WriteAllText("gitdir: ../.git/modules/sub11 \t\v\r\n");
218219

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

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

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

@@ -363,7 +369,7 @@ public void GetSubmoduleHeadCommitSha()
363369
var submoduleGitDir = temp.CreateDirectory();
364370

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

368374
var submoduleRefsHeadsDir = submoduleGitDir.CreateDirectory("refs").CreateDirectory("heads");
369375
submoduleRefsHeadsDir.CreateFile("master").WriteAllText("0000000000000000000000000000000000000000");

src/Microsoft.Build.Tasks.Git/GitDataReader/GitRepository.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ internal static string GetWorkingDirectory(GitConfig config, string gitDirectory
174174
// Path in gitdir file must be absolute.
175175
if (!PathUtils.IsAbsolute(workingDirectory))
176176
{
177-
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsNotAbsolute, gitdirFilePath));
177+
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsNotAbsolute, gitdirFilePath, workingDirectory));
178178
}
179179

180180
try
@@ -183,7 +183,7 @@ internal static string GetWorkingDirectory(GitConfig config, string gitDirectory
183183
}
184184
catch
185185
{
186-
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, gitdirFilePath));
186+
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, gitdirFilePath, workingDirectory));
187187
}
188188
}
189189

@@ -533,8 +533,7 @@ private static string ReadDotGitFile(string path)
533533
throw new InvalidDataException(string.Format(Resources.FormatOfFileIsInvalid, path));
534534
}
535535

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

539538
try
540539
{
@@ -543,7 +542,7 @@ private static string ReadDotGitFile(string path)
543542
}
544543
catch
545544
{
546-
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, path));
545+
throw new InvalidDataException(string.Format(Resources.PathSpecifiedInFileIsInvalid, path, link));
547546
}
548547
}
549548

src/Microsoft.Build.Tasks.Git/Resources.resx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="PathMustBeAbsolute" xml:space="preserve">
121-
<value>Path must be absolute</value>
121+
<value>Path must be absolute.</value>
122122
</data>
123123
<data name="PathMustBeFilePath" xml:space="preserve">
124-
<value>Path must be a file path</value>
124+
<value>Path must be a file path.</value>
125125
</data>
126126
<data name="ErrorReadingGitRepositoryInformation" xml:space="preserve">
127127
<value>Error reading git repository information: {0}</value>
@@ -130,10 +130,10 @@
130130
<value>Unsupported repository version {0}. Only versions up to {1} are supported.</value>
131131
</data>
132132
<data name="PathSpecifiedInFileIsNotAbsolute" xml:space="preserve">
133-
<value>Path specified in file '{0}' is not absolute.</value>
133+
<value>Path specified in file '{0}' is not absolute: '{1}'.</value>
134134
</data>
135135
<data name="PathSpecifiedInFileIsInvalid" xml:space="preserve">
136-
<value>Path specified in file '{0}' is invalid.</value>
136+
<value>Path specified in file '{0}' is invalid: '{1}'.</value>
137137
</data>
138138
<data name="ValueOfIsNotValidPath" xml:space="preserve">
139139
<value>The value of {0} is not a valid path: '{1}'.</value>
@@ -160,16 +160,16 @@
160160
<value>Configuration file recursion exceeded maximum allowed depth of {0}.</value>
161161
</data>
162162
<data name="SubmoduleWithoutCommit" xml:space="preserve">
163-
<value>Submodule '{0}' doesn't have any commit</value>
163+
<value>Submodule '{0}' doesn't have any commit.</value>
164164
</data>
165165
<data name="InvalidSubmoduleUrl" xml:space="preserve">
166-
<value>The URL of submodule '{0}' is missing or invalid: '{1}'</value>
166+
<value>The URL of submodule '{0}' is missing or invalid: '{1}'.</value>
167167
</data>
168168
<data name="InvalidSubmodulePath" xml:space="preserve">
169-
<value>The path of submodule '{0}' is missing or invalid: '{1}'</value>
169+
<value>The path of submodule '{0}' is missing or invalid: '{1}'.</value>
170170
</data>
171171
<data name="SourceCodeWontBeAvailableViaSourceLink" xml:space="preserve">
172-
<value>{0} -- the source code won't be available via Source Link.</value>
172+
<value>{0} The source code won't be available via Source Link.</value>
173173
</data>
174174
<data name="RepositoryHasNoCommit" xml:space="preserve">
175175
<value>Repository has no commit.</value>
@@ -190,6 +190,6 @@
190190
<value>The value of {0} is not a valid configuration scope: '{1}'.</value>
191191
</data>
192192
<data name="HomeRelativePathsAreNotAllowed" xml:space="preserve">
193-
<value>Home relative paths are not allowed when {0} is '{1}': '{2}'</value>
193+
<value>Home relative paths are not allowed when {0} is '{1}': '{2}'.</value>
194194
</data>
195195
</root>

src/Microsoft.Build.Tasks.Git/xlf/Resources.cs.xlf

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<note />
1919
</trans-unit>
2020
<trans-unit id="HomeRelativePathsAreNotAllowed">
21-
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'</source>
22-
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'</target>
21+
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'.</source>
22+
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'.</target>
2323
<note />
2424
</trans-unit>
2525
<trans-unit id="InvalidFormatOfFileAtPath">
@@ -43,33 +43,33 @@
4343
<note />
4444
</trans-unit>
4545
<trans-unit id="InvalidSubmodulePath">
46-
<source>The path of submodule '{0}' is missing or invalid: '{1}'</source>
47-
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'</target>
46+
<source>The path of submodule '{0}' is missing or invalid: '{1}'.</source>
47+
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'.</target>
4848
<note />
4949
</trans-unit>
5050
<trans-unit id="InvalidSubmoduleUrl">
51-
<source>The URL of submodule '{0}' is missing or invalid: '{1}'</source>
52-
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'</target>
51+
<source>The URL of submodule '{0}' is missing or invalid: '{1}'.</source>
52+
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'.</target>
5353
<note />
5454
</trans-unit>
5555
<trans-unit id="PathMustBeAbsolute">
56-
<source>Path must be absolute</source>
57-
<target state="new">Path must be absolute</target>
56+
<source>Path must be absolute.</source>
57+
<target state="new">Path must be absolute.</target>
5858
<note />
5959
</trans-unit>
6060
<trans-unit id="PathMustBeFilePath">
61-
<source>Path must be a file path</source>
62-
<target state="new">Path must be a file path</target>
61+
<source>Path must be a file path.</source>
62+
<target state="new">Path must be a file path.</target>
6363
<note />
6464
</trans-unit>
6565
<trans-unit id="PathSpecifiedInFileIsInvalid">
66-
<source>Path specified in file '{0}' is invalid.</source>
67-
<target state="new">Path specified in file '{0}' is invalid.</target>
66+
<source>Path specified in file '{0}' is invalid: '{1}'.</source>
67+
<target state="new">Path specified in file '{0}' is invalid: '{1}'.</target>
6868
<note />
6969
</trans-unit>
7070
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
71-
<source>Path specified in file '{0}' is not absolute.</source>
72-
<target state="new">Path specified in file '{0}' is not absolute.</target>
71+
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
72+
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
7373
<note />
7474
</trans-unit>
7575
<trans-unit id="RecursionDetectedWhileResolvingReference">
@@ -98,13 +98,13 @@
9898
<note />
9999
</trans-unit>
100100
<trans-unit id="SourceCodeWontBeAvailableViaSourceLink">
101-
<source>{0} -- the source code won't be available via Source Link.</source>
102-
<target state="new">{0} -- the source code won't be available via Source Link.</target>
101+
<source>{0} The source code won't be available via Source Link.</source>
102+
<target state="new">{0} The source code won't be available via Source Link.</target>
103103
<note />
104104
</trans-unit>
105105
<trans-unit id="SubmoduleWithoutCommit">
106-
<source>Submodule '{0}' doesn't have any commit</source>
107-
<target state="new">Submodule '{0}' doesn't have any commit</target>
106+
<source>Submodule '{0}' doesn't have any commit.</source>
107+
<target state="new">Submodule '{0}' doesn't have any commit.</target>
108108
<note />
109109
</trans-unit>
110110
<trans-unit id="UnableToLocateRepository">

src/Microsoft.Build.Tasks.Git/xlf/Resources.de.xlf

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<note />
1919
</trans-unit>
2020
<trans-unit id="HomeRelativePathsAreNotAllowed">
21-
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'</source>
22-
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'</target>
21+
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'.</source>
22+
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'.</target>
2323
<note />
2424
</trans-unit>
2525
<trans-unit id="InvalidFormatOfFileAtPath">
@@ -43,33 +43,33 @@
4343
<note />
4444
</trans-unit>
4545
<trans-unit id="InvalidSubmodulePath">
46-
<source>The path of submodule '{0}' is missing or invalid: '{1}'</source>
47-
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'</target>
46+
<source>The path of submodule '{0}' is missing or invalid: '{1}'.</source>
47+
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'.</target>
4848
<note />
4949
</trans-unit>
5050
<trans-unit id="InvalidSubmoduleUrl">
51-
<source>The URL of submodule '{0}' is missing or invalid: '{1}'</source>
52-
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'</target>
51+
<source>The URL of submodule '{0}' is missing or invalid: '{1}'.</source>
52+
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'.</target>
5353
<note />
5454
</trans-unit>
5555
<trans-unit id="PathMustBeAbsolute">
56-
<source>Path must be absolute</source>
57-
<target state="new">Path must be absolute</target>
56+
<source>Path must be absolute.</source>
57+
<target state="new">Path must be absolute.</target>
5858
<note />
5959
</trans-unit>
6060
<trans-unit id="PathMustBeFilePath">
61-
<source>Path must be a file path</source>
62-
<target state="new">Path must be a file path</target>
61+
<source>Path must be a file path.</source>
62+
<target state="new">Path must be a file path.</target>
6363
<note />
6464
</trans-unit>
6565
<trans-unit id="PathSpecifiedInFileIsInvalid">
66-
<source>Path specified in file '{0}' is invalid.</source>
67-
<target state="new">Path specified in file '{0}' is invalid.</target>
66+
<source>Path specified in file '{0}' is invalid: '{1}'.</source>
67+
<target state="new">Path specified in file '{0}' is invalid: '{1}'.</target>
6868
<note />
6969
</trans-unit>
7070
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
71-
<source>Path specified in file '{0}' is not absolute.</source>
72-
<target state="new">Path specified in file '{0}' is not absolute.</target>
71+
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
72+
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
7373
<note />
7474
</trans-unit>
7575
<trans-unit id="RecursionDetectedWhileResolvingReference">
@@ -98,13 +98,13 @@
9898
<note />
9999
</trans-unit>
100100
<trans-unit id="SourceCodeWontBeAvailableViaSourceLink">
101-
<source>{0} -- the source code won't be available via Source Link.</source>
102-
<target state="new">{0} -- the source code won't be available via Source Link.</target>
101+
<source>{0} The source code won't be available via Source Link.</source>
102+
<target state="new">{0} The source code won't be available via Source Link.</target>
103103
<note />
104104
</trans-unit>
105105
<trans-unit id="SubmoduleWithoutCommit">
106-
<source>Submodule '{0}' doesn't have any commit</source>
107-
<target state="new">Submodule '{0}' doesn't have any commit</target>
106+
<source>Submodule '{0}' doesn't have any commit.</source>
107+
<target state="new">Submodule '{0}' doesn't have any commit.</target>
108108
<note />
109109
</trans-unit>
110110
<trans-unit id="UnableToLocateRepository">

src/Microsoft.Build.Tasks.Git/xlf/Resources.es.xlf

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<note />
1919
</trans-unit>
2020
<trans-unit id="HomeRelativePathsAreNotAllowed">
21-
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'</source>
22-
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'</target>
21+
<source>Home relative paths are not allowed when {0} is '{1}': '{2}'.</source>
22+
<target state="new">Home relative paths are not allowed when {0} is '{1}': '{2}'.</target>
2323
<note />
2424
</trans-unit>
2525
<trans-unit id="InvalidFormatOfFileAtPath">
@@ -43,33 +43,33 @@
4343
<note />
4444
</trans-unit>
4545
<trans-unit id="InvalidSubmodulePath">
46-
<source>The path of submodule '{0}' is missing or invalid: '{1}'</source>
47-
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'</target>
46+
<source>The path of submodule '{0}' is missing or invalid: '{1}'.</source>
47+
<target state="new">The path of submodule '{0}' is missing or invalid: '{1}'.</target>
4848
<note />
4949
</trans-unit>
5050
<trans-unit id="InvalidSubmoduleUrl">
51-
<source>The URL of submodule '{0}' is missing or invalid: '{1}'</source>
52-
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'</target>
51+
<source>The URL of submodule '{0}' is missing or invalid: '{1}'.</source>
52+
<target state="new">The URL of submodule '{0}' is missing or invalid: '{1}'.</target>
5353
<note />
5454
</trans-unit>
5555
<trans-unit id="PathMustBeAbsolute">
56-
<source>Path must be absolute</source>
57-
<target state="new">Path must be absolute</target>
56+
<source>Path must be absolute.</source>
57+
<target state="new">Path must be absolute.</target>
5858
<note />
5959
</trans-unit>
6060
<trans-unit id="PathMustBeFilePath">
61-
<source>Path must be a file path</source>
62-
<target state="new">Path must be a file path</target>
61+
<source>Path must be a file path.</source>
62+
<target state="new">Path must be a file path.</target>
6363
<note />
6464
</trans-unit>
6565
<trans-unit id="PathSpecifiedInFileIsInvalid">
66-
<source>Path specified in file '{0}' is invalid.</source>
67-
<target state="new">Path specified in file '{0}' is invalid.</target>
66+
<source>Path specified in file '{0}' is invalid: '{1}'.</source>
67+
<target state="new">Path specified in file '{0}' is invalid: '{1}'.</target>
6868
<note />
6969
</trans-unit>
7070
<trans-unit id="PathSpecifiedInFileIsNotAbsolute">
71-
<source>Path specified in file '{0}' is not absolute.</source>
72-
<target state="new">Path specified in file '{0}' is not absolute.</target>
71+
<source>Path specified in file '{0}' is not absolute: '{1}'.</source>
72+
<target state="new">Path specified in file '{0}' is not absolute: '{1}'.</target>
7373
<note />
7474
</trans-unit>
7575
<trans-unit id="RecursionDetectedWhileResolvingReference">
@@ -98,13 +98,13 @@
9898
<note />
9999
</trans-unit>
100100
<trans-unit id="SourceCodeWontBeAvailableViaSourceLink">
101-
<source>{0} -- the source code won't be available via Source Link.</source>
102-
<target state="new">{0} -- the source code won't be available via Source Link.</target>
101+
<source>{0} The source code won't be available via Source Link.</source>
102+
<target state="new">{0} The source code won't be available via Source Link.</target>
103103
<note />
104104
</trans-unit>
105105
<trans-unit id="SubmoduleWithoutCommit">
106-
<source>Submodule '{0}' doesn't have any commit</source>
107-
<target state="new">Submodule '{0}' doesn't have any commit</target>
106+
<source>Submodule '{0}' doesn't have any commit.</source>
107+
<target state="new">Submodule '{0}' doesn't have any commit.</target>
108108
<note />
109109
</trans-unit>
110110
<trans-unit id="UnableToLocateRepository">

0 commit comments

Comments
 (0)