diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index ce358dc73f..ce25086ece 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Text; +using GitTools; using GitTools.Testing; using GitVersion; using NUnit.Framework; @@ -66,4 +69,25 @@ public void WorkingDirectoryWithoutGitFolderCrashesWithInformativeMessage() var results = GitVersionHelper.ExecuteIn(Environment.SystemDirectory, null, isTeamCity: false, logToFile: false); results.Output.ShouldContain("Can't find the .git directory in"); } + + [Test] + [Category("NoMono")] + [Description("Doesn't work on Mono/Unix because of the path heuristics that needs to be done there in order to figure out whether the first argument actually is a path.")] + public void WorkingDirectoryDoesNotExistCrashesWithInformativeMessage() + { + var workingDirectory = Path.Combine(Environment.CurrentDirectory, Guid.NewGuid().ToString("N")); + var gitVersion = Path.Combine(PathHelper.GetCurrentDirectory(), "GitVersion.exe"); + var output = new StringBuilder(); + var exitCode = ProcessHelper.Run( + s => output.AppendLine(s), + s => output.AppendLine(s), + null, + gitVersion, + workingDirectory, + Environment.CurrentDirectory); + + exitCode.ShouldNotBe(0); + var outputString = output.ToString(); + outputString.ShouldContain(string.Format("The working directory '{0}' does not exist.", workingDirectory), () => outputString); + } } \ No newline at end of file diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 03e7589dde..f9268cf655 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -64,6 +64,16 @@ static int VerifyArgumentsAndRun() } ConfigureLogging(arguments); + + if (!Directory.Exists(arguments.TargetPath)) + { + Logger.WriteWarning(string.Format("The working directory '{0}' does not exist.", arguments.TargetPath)); + } + else + { + Logger.WriteInfo("Working directory: " + arguments.TargetPath); + } + if (arguments.Init) { ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter()); @@ -80,8 +90,6 @@ static int VerifyArgumentsAndRun() arguments.Output = OutputType.BuildServer; } - Logger.WriteInfo("Working directory: " + arguments.TargetPath); - SpecifiedArgumentRunner.Run(arguments, fileSystem); } catch (WarningException exception) @@ -98,9 +106,17 @@ static int VerifyArgumentsAndRun() if (arguments != null) { Logger.WriteInfo(string.Empty); - Logger.WriteInfo("Here is the current git graph (please include in issue): "); + Logger.WriteInfo("Attempting to show the current git graph (please include in issue): "); Logger.WriteInfo("Showing max of 100 commits"); - GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); + + try + { + GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100); + } + catch (Exception dumpGraphException) + { + Logger.WriteError("Couldn't dump the git graph due to the following error: " + dumpGraphException); + } } return 1; }