Skip to content

Commit 87495e3

Browse files
committed
Added support for forward slashes (unix paths) in command line arguments
1 parent 8df7cf8 commit 87495e3

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,11 @@ public void other_arguments_can_be_parsed_after_nofetch()
284284
arguments.NoFetch = true;
285285
arguments.Proj = "foo.sln";
286286
}
287+
288+
[Test]
289+
public void log_path_can_contain_forward_slash()
290+
{
291+
var arguments = ArgumentParser.ParseArguments("-l /some/path");
292+
arguments.LogFilePath.ShouldBe("/some/path");
293+
}
287294
}

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ public void InvalidArgumentsExitCodeShouldNotBeZero()
4545
result.Output.ShouldContain("Could not parse command line parameter '/invalid-argument'");
4646
}
4747
}
48+
49+
[Test]
50+
public void LogPathContainsForwardSlash()
51+
{
52+
using (var fixture = new EmptyRepositoryFixture())
53+
{
54+
fixture.MakeATaggedCommit("1.2.3");
55+
fixture.MakeACommit();
56+
57+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: @" /l ""/some/path""", logToFile: false);
58+
59+
result.ExitCode.ShouldBe(0);
60+
result.Output.ShouldContain(@"""MajorMinorPatch"":""1.2.4""");
61+
}
62+
}
4863
}

src/GitVersionExe/ArgumentParser.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,15 @@ static NameValueCollection CollectSwitchesAndValuesFromArguments(List<string> na
316316
var args = new NameValueCollection();
317317

318318
string currentKey = null;
319+
var isBooleanArgument = true;
319320
for (var index = 0; index < namedArguments.Count; index = index + 1)
320321
{
321322
var arg = namedArguments[index];
322-
//If this is a switch, create new name/value entry for it, with a null value.
323-
if (IsSwitchArgument(arg))
323+
// If the current (previous) argument doesn't require a parameter and this is a switch, create new name/value entry for it, with a null value.
324+
if (isBooleanArgument && IsSwitchArgument(arg))
324325
{
325326
currentKey = arg;
327+
isBooleanArgument = IsBooleanArgument(arg);
326328
args.Add(currentKey, null);
327329
}
328330
//If this is a value (not a switch)
@@ -338,14 +340,18 @@ static NameValueCollection CollectSwitchesAndValuesFromArguments(List<string> na
338340
{
339341
args.Add(currentKey, arg);
340342
}
343+
344+
// Reset the boolean argument flag so the next argument won't be ignored.
345+
isBooleanArgument = true;
341346
}
342347
}
343348
return args;
344349
}
345350

346351
static bool IsSwitchArgument(string value)
347352
{
348-
return value != null && (value.StartsWith("-") || value.StartsWith("/"))
353+
return value != null
354+
&& (value.StartsWith("-") || value.StartsWith("/"))
349355
&& !Regex.Match(value, @"/\w+:").Success; //Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names.
350356
}
351357

@@ -376,5 +382,18 @@ static bool IsHelp(string singleArgument)
376382
IsSwitch("help", singleArgument) ||
377383
IsSwitch("?", singleArgument);
378384
}
385+
386+
static bool IsBooleanArgument(string switchName)
387+
{
388+
var booleanArguments = new[]
389+
{
390+
"init",
391+
"updateassemblyinfo",
392+
"ensureassemblyinfo",
393+
"nofetch"
394+
};
395+
396+
return booleanArguments.Contains(switchName, StringComparer.OrdinalIgnoreCase);
397+
}
379398
}
380399
}

0 commit comments

Comments
 (0)