Skip to content

Commit e71919d

Browse files
committed
Merge branch 'feature/improved-exception-handling'
2 parents cf893ff + f0dbaf0 commit e71919d

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

GitVersion.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ II.2.12 <HandlesEvent />
569569
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
570570
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
571571
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
572+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
572573
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
573574
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
574575
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>

GitVersionCore.Tests/Helpers/GitTestExtensions.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,24 @@ public static void DumpGraph(this IRepository repository)
1515
{
1616
var output = new StringBuilder();
1717

18-
ProcessHelper.Run(
19-
o => output.AppendLine(o),
20-
e => output.AppendLineFormat("ERROR: {0}", e),
21-
null,
22-
"git",
23-
@"log --graph --abbrev-commit --decorate --date=relative --all --remotes=*",
24-
repository.Info.Path);
18+
try
19+
{
20+
ProcessHelper.Run(
21+
o => output.AppendLine(o),
22+
e => output.AppendLineFormat("ERROR: {0}", e),
23+
null,
24+
"git",
25+
@"log --graph --abbrev-commit --decorate --date=relative --all --remotes=*",
26+
repository.Info.Path);
27+
}
28+
catch (FileNotFoundException exception)
29+
{
30+
if (exception.FileName != "git")
31+
throw;
32+
33+
output.AppendLine("Could not execute 'git log' due to the following error:");
34+
output.AppendLine(exception.ToString());
35+
}
2536

2637
Trace.Write(output.ToString());
2738
}

GitVersionCore/Helpers/ProcessHelper.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace GitVersion.Helpers
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.ComponentModel;
56
using System.Diagnostics;
67
using System.IO;
78
using System.Runtime.InteropServices;
@@ -20,8 +21,24 @@ public static Process Start(ProcessStartInfo startInfo)
2021
{
2122
using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox))
2223
{
23-
process = Process.Start(startInfo);
24-
process.PriorityClass = ProcessPriorityClass.Idle;
24+
try
25+
{
26+
process = Process.Start(startInfo);
27+
process.PriorityClass = ProcessPriorityClass.Idle;
28+
}
29+
catch (Win32Exception exception)
30+
{
31+
// NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 @asbjornu
32+
if (exception.NativeErrorCode == 2)
33+
{
34+
throw new FileNotFoundException(String.Format("The executable file '{0}' could not be found.",
35+
startInfo.FileName),
36+
startInfo.FileName,
37+
exception);
38+
}
39+
40+
throw;
41+
}
2542
}
2643
}
2744

@@ -32,10 +49,12 @@ public static Process Start(ProcessStartInfo startInfo)
3249
public static int Run(Action<string> output, Action<string> errorOutput, TextReader input, string exe, string args, string workingDirectory, params KeyValuePair<string, string>[] environmentalVariables)
3350
{
3451
if (String.IsNullOrEmpty(exe))
35-
throw new FileNotFoundException();
52+
throw new ArgumentNullException("exe");
3653
if (output == null)
3754
throw new ArgumentNullException("output");
3855

56+
workingDirectory = workingDirectory ?? Environment.CurrentDirectory;
57+
3958
var psi = new ProcessStartInfo
4059
{
4160
UseShellExecute = false,
@@ -45,7 +64,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
4564
WindowStyle = ProcessWindowStyle.Hidden,
4665
CreateNoWindow = true,
4766
ErrorDialog = false,
48-
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory,
67+
WorkingDirectory = workingDirectory,
4968
FileName = exe,
5069
Arguments = args
5170
};
@@ -57,7 +76,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
5776
psi.EnvironmentVariables.Remove(environmentalVariable.Key);
5877
}
5978

60-
using (var process = Process.Start(psi))
79+
using (var process = Start(psi))
6180
using (var mreOut = new ManualResetEvent(false))
6281
using (var mreErr = new ManualResetEvent(false))
6382
{
@@ -120,5 +139,4 @@ public ChangeErrorMode(ErrorModes mode)
120139
static extern int SetErrorMode(int newMode);
121140
}
122141
}
123-
124142
}

GitVersionTask/NugetAssets/GitVersionTask.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)..\</SolutionDir>
55
<IntermediateOutputPath Condition="$(IntermediateOutputPath) == '' Or $(IntermediateOutputPath) == '*Undefined*'">$(MSBuildProjectDirectory)obj\$(Configuration)\</IntermediateOutputPath>
6+
<GitVersionNoFetchEnabled Condition="$(GitVersionNoFetchEnabled) == ''">false</GitVersionNoFetchEnabled>
67
</PropertyGroup>
78

89
<UsingTask
@@ -35,7 +36,7 @@
3536
</ItemGroup>
3637

3738

38-
<GetVersion SolutionDirectory="$(SolutionDir)">
39+
<GetVersion SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersionNoFetchEnabled)">
3940
<Output TaskParameter="Major" PropertyName="GfvMajor" />
4041
<Output TaskParameter="Minor" PropertyName="GfvMinor" />
4142
<Output TaskParameter="Patch" PropertyName="GfvPatch" />

0 commit comments

Comments
 (0)