Skip to content

Commit 98f8b97

Browse files
authored
Merge pull request #908 from asbjornu/feature/showconfig-throws-in-git-bash
Showconfig throws in Git Bash on Windows
2 parents 38b8fb1 + 1765942 commit 98f8b97

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Text;
5+
using GitTools;
36
using GitTools.Testing;
47
using GitVersion;
58
using NUnit.Framework;
@@ -66,4 +69,25 @@ public void WorkingDirectoryWithoutGitFolderCrashesWithInformativeMessage()
6669
var results = GitVersionHelper.ExecuteIn(Environment.SystemDirectory, null, isTeamCity: false, logToFile: false);
6770
results.Output.ShouldContain("Can't find the .git directory in");
6871
}
72+
73+
[Test]
74+
[Category("NoMono")]
75+
[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.")]
76+
public void WorkingDirectoryDoesNotExistCrashesWithInformativeMessage()
77+
{
78+
var workingDirectory = Path.Combine(Environment.CurrentDirectory, Guid.NewGuid().ToString("N"));
79+
var gitVersion = Path.Combine(PathHelper.GetCurrentDirectory(), "GitVersion.exe");
80+
var output = new StringBuilder();
81+
var exitCode = ProcessHelper.Run(
82+
s => output.AppendLine(s),
83+
s => output.AppendLine(s),
84+
null,
85+
gitVersion,
86+
workingDirectory,
87+
Environment.CurrentDirectory);
88+
89+
exitCode.ShouldNotBe(0);
90+
var outputString = output.ToString();
91+
outputString.ShouldContain(string.Format("The working directory '{0}' does not exist.", workingDirectory), () => outputString);
92+
}
6993
}

src/GitVersionExe/Program.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ static int VerifyArgumentsAndRun()
6464
}
6565

6666
ConfigureLogging(arguments);
67+
68+
if (!Directory.Exists(arguments.TargetPath))
69+
{
70+
Logger.WriteWarning(string.Format("The working directory '{0}' does not exist.", arguments.TargetPath));
71+
}
72+
else
73+
{
74+
Logger.WriteInfo("Working directory: " + arguments.TargetPath);
75+
}
76+
6777
if (arguments.Init)
6878
{
6979
ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter());
@@ -80,8 +90,6 @@ static int VerifyArgumentsAndRun()
8090
arguments.Output = OutputType.BuildServer;
8191
}
8292

83-
Logger.WriteInfo("Working directory: " + arguments.TargetPath);
84-
8593
SpecifiedArgumentRunner.Run(arguments, fileSystem);
8694
}
8795
catch (WarningException exception)
@@ -98,9 +106,17 @@ static int VerifyArgumentsAndRun()
98106
if (arguments != null)
99107
{
100108
Logger.WriteInfo(string.Empty);
101-
Logger.WriteInfo("Here is the current git graph (please include in issue): ");
109+
Logger.WriteInfo("Attempting to show the current git graph (please include in issue): ");
102110
Logger.WriteInfo("Showing max of 100 commits");
103-
GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
111+
112+
try
113+
{
114+
GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
115+
}
116+
catch (Exception dumpGraphException)
117+
{
118+
Logger.WriteError("Couldn't dump the git graph due to the following error: " + dumpGraphException);
119+
}
104120
}
105121
return 1;
106122
}

0 commit comments

Comments
 (0)