Skip to content

Tests fail: Can't find git #440

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 9 commits into from
Jun 7, 2015
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
1 change: 1 addition & 0 deletions GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ II.2.12 <HandlesEvent />
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
Expand Down
25 changes: 18 additions & 7 deletions GitVersionCore.Tests/Helpers/GitTestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ public static void DumpGraph(this IRepository repository)
{
var output = new StringBuilder();

ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all",
repository.Info.Path);
try
{
ProcessHelper.Run(
o => output.AppendLine(o),
e => output.AppendLineFormat("ERROR: {0}", e),
null,
"git",
@"log --graph --abbrev-commit --decorate --date=relative --all",
repository.Info.Path);
}
catch (FileNotFoundException exception)
{
if (exception.FileName != "git")
throw;

output.AppendLine("Could not execute 'git log' due to the following error:");
output.AppendLine(exception.ToString());
}

Trace.Write(output.ToString());
}
Expand Down
30 changes: 24 additions & 6 deletions GitVersionCore/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace GitVersion.Helpers
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
Expand All @@ -20,8 +21,24 @@ public static Process Start(ProcessStartInfo startInfo)
{
using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox))
{
process = Process.Start(startInfo);
process.PriorityClass = ProcessPriorityClass.Idle;
try
{
process = Process.Start(startInfo);
process.PriorityClass = ProcessPriorityClass.Idle;
}
catch (Win32Exception exception)
{
// NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 @asbjornu
if (exception.NativeErrorCode == 2)
{
throw new FileNotFoundException(String.Format("The executable file '{0}' could not be found.",
startInfo.FileName),
startInfo.FileName,
exception);
}

throw;
}
}
}

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

workingDirectory = workingDirectory ?? Environment.CurrentDirectory;

var psi = new ProcessStartInfo
{
UseShellExecute = false,
Expand All @@ -45,7 +64,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
ErrorDialog = false,
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory,
WorkingDirectory = workingDirectory,
FileName = exe,
Arguments = args
};
Expand All @@ -57,7 +76,7 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
psi.EnvironmentVariables.Remove(environmentalVariable.Key);
}

using (var process = Process.Start(psi))
using (var process = Start(psi))
using (var mreOut = new ManualResetEvent(false))
using (var mreErr = new ManualResetEvent(false))
{
Expand Down Expand Up @@ -120,5 +139,4 @@ public ChangeErrorMode(ErrorModes mode)
static extern int SetErrorMode(int newMode);
}
}

}
3 changes: 2 additions & 1 deletion GitVersionTask/NugetAssets/GitVersionTask.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)..\</SolutionDir>
<IntermediateOutputPath Condition="$(IntermediateOutputPath) == '' Or $(IntermediateOutputPath) == '*Undefined*'">$(MSBuildProjectDirectory)obj\$(Configuration)\</IntermediateOutputPath>
<GitVersionNoFetchEnabled Condition="$(GitVersionNoFetchEnabled) == ''">false</GitVersionNoFetchEnabled>
</PropertyGroup>

<UsingTask
Expand Down Expand Up @@ -35,7 +36,7 @@
</ItemGroup>


<GetVersion SolutionDirectory="$(SolutionDir)">
<GetVersion SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersionNoFetchEnabled)">
<Output TaskParameter="Major" PropertyName="GfvMajor" />
<Output TaskParameter="Minor" PropertyName="GfvMinor" />
<Output TaskParameter="Patch" PropertyName="GfvPatch" />
Expand Down