From f8a515c7de9452bc7a62e0211f14cea09c0b0dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 16 Jun 2016 11:13:17 +0200 Subject: [PATCH 1/3] try/catch the git graph dump --- src/GitVersionExe/Program.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 03e7589dde..90503595f8 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -98,9 +98,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; } From d7cacc5365e395249140e543941aed1a9c4a1c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 16 Jun 2016 11:25:35 +0200 Subject: [PATCH 2/3] Warn if the working directory doesn't exist. --- src/GitVersionExe/Program.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index 90503595f8..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) From 17659421e6ff44e8c48d791c8ef93ed8bd5ffe77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Thu, 16 Jun 2016 11:45:05 +0200 Subject: [PATCH 3/3] Added test for having a non-existing path as working directory --- .../ExecCmdLineArgumentTest.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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