Skip to content

GH2160: Set application exit code #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ public void CheckBuildServerVerbosityConsole(string verbosityArg, string expecte
}

[Test]
public void WorkingDirectoryWithoutGitFolderCrashesWithInformativeMessage()
public void WorkingDirectoryWithoutGitFolderFailsWithInformativeMessage()
{
var results = GitVersionHelper.ExecuteIn(Environment.SystemDirectory, null, false);
results.Output.ShouldContain("Can't find the .git directory in");
var result = GitVersionHelper.ExecuteIn(Environment.SystemDirectory, null, false);

result.ExitCode.ShouldNotBe(0);
result.Output.ShouldContain("Can't find the .git directory in");
}

[Test]
public void WorkingDirectoryDoesNotExistCrashesWithInformativeMessage()
public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
{
var workingDirectory = Path.Combine(PathHelper.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
var executable = PathHelper.GetExecutable();
Expand All @@ -98,7 +100,7 @@ public void WorkingDirectoryDoesNotExistCrashesWithInformativeMessage()
args,
PathHelper.GetCurrentDirectory());

exitCode.ShouldBe(0);
exitCode.ShouldNotBe(0);
var outputString = output.ToString();
outputString.ShouldContain($"The working directory '{workingDirectory}' does not exist.", () => outputString);
}
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersionExe/GitVersionApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public Task StartAsync(CancellationToken cancellationToken)
{
var arguments = options.Value;
log.Verbosity = arguments.Verbosity;
gitVersionExecutor.Execute(arguments);
System.Environment.ExitCode = gitVersionExecutor.Execute(arguments);
}
catch (Exception exception)
{
Console.Error.WriteLine(exception.Message);
System.Environment.ExitCode = 1;
}

applicationLifetime.StopApplication();
Expand Down