Skip to content

Commit 5d16fac

Browse files
committed
Merge pull request #112 from JakeGinnivan/ExecAndProjArguments
Added /exec and /proj arguments
2 parents 9126606 + e2659cf commit 5d16fac

19 files changed

+240
-145
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*.vspscc
3232
.builds
3333
*.dotCover
34+
*.orig
3435

3536
## If you have NuGet Package Restore enabled, uncomment this
3637
packages/

AcceptanceTests/NoTagsInRepositorySpecification.RunSpecification.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/NoTagsInRepositoryWithNextVersionTxtSpecification.RunSpecification.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/RepositorySpecification.RunSpecification.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForOneCommit.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.ForTenCommitsCommit.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithApplicableNextVersionTxtSpecification.Run.approved.txt.orig

-1
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithNoNextVersionTxtSpecification.RunSpecification.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.Run.approved.txt.orig

-1
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithOneCommit.approved.txt.orig

-17
This file was deleted.

AcceptanceTests/TagFollowedByCommitsWithRedundantNextVersionTxtSpecification.WithTenCommit.approved.txt.orig

-17
This file was deleted.

GitVersion.sln

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionTask", "GitVersionTask\GitVersionTask.csproj", "{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}"
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AcceptanceTests", "AcceptanceTests\AcceptanceTests.csproj", "{BF905F84-382C-440D-92F5-C61108626D8D}"
13+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EFFC5D6-88D0-49D9-BB53-E1B7EB49DD45}"
14+
ProjectSection(SolutionItems) = preProject
15+
LICENSE = LICENSE
16+
README.md = README.md
17+
EndProjectSection
1318
EndProject
1419
Global
1520
GlobalSection(SolutionConfigurationPlatforms) = preSolution

GitVersion/ArgumentParser.cs

+24
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,30 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
8888
continue;
8989
}
9090

91+
if (IsSwitch("exec", name))
92+
{
93+
arguments.Exec = value;
94+
continue;
95+
}
96+
97+
if (IsSwitch("execargs", name))
98+
{
99+
arguments.ExecArgs = value;
100+
continue;
101+
}
102+
103+
if (IsSwitch("proj", name))
104+
{
105+
arguments.Proj = value;
106+
continue;
107+
}
108+
109+
if (IsSwitch("projargs", name))
110+
{
111+
arguments.ProjArgs = value;
112+
continue;
113+
}
114+
91115
if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
92116
{
93117
arguments.VersionPart = value.ToLower();

GitVersion/Arguments.cs

+5
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ public Arguments()
3131
public string VersionPart;
3232

3333
public OutputType Output;
34+
35+
public string Proj;
36+
public string ProjArgs;
37+
public string Exec;
38+
public string ExecArgs;
3439
}
3540
}

GitVersion/GitVersion.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<Compile Include="HelpWriter.cs" />
8383
<Compile Include="GitFlow\ReleaseInformation.cs" />
8484
<Compile Include="GitFlow\ReleaseInformationCalculator.cs" />
85+
<Compile Include="ProcessHelper.cs" />
8586
<Compile Include="ReleaseDate.cs" />
8687
<Compile Include="ReleaseDateFinder.cs" />
8788
<Compile Include="SemanticVersionTag.cs" />

GitVersion/HelpWriter.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ public static void Write()
1111
1212
GitVersion [path] [/l logFilePath]
1313
14-
path The directory containing .git. If not defined current directory is used.
15-
/url Url to remote git repository.
16-
/b Name of the branch to use on the remote repository, must be used in combination with /url.
17-
/u Username in case authentication is required.
18-
/p Password in case authentication is required.
19-
/output Determines the output to the console. Can be either 'json' or 'buildserver', will default to 'json'.
20-
/l Path to logfile.
14+
path The directory containing .git. If not defined current directory is used.
15+
/url Url to remote git repository.
16+
/b Name of the branch to use on the remote repository, must be used in combination with /url.
17+
/u Username in case authentication is required.
18+
/p Password in case authentication is required.
19+
/output Determines the output to the console. Can be either 'json' or 'buildserver', will default to 'json'.
20+
/l Path to logfile.
21+
/exec Executes target executable making GitVersion variables available as environmental variables
22+
/execargs Arguments for the executable specified by /exec
23+
/proj Build a msbuild file, GitVersion variables will be passed as msbuild properties
24+
/projargs Additional arguments to pass to msbuild
2125
";
2226
Console.Write(message);
2327
}

GitVersion/ProcessHelper.cs

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Runtime.InteropServices;
7+
using System.Threading;
8+
9+
static class ProcessHelper
10+
{
11+
private static volatile object _lockObject = new object();
12+
13+
// http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/f6069441-4ab1-4299-ad6a-b8bb9ed36be3
14+
public static Process Start(ProcessStartInfo startInfo)
15+
{
16+
Process process;
17+
18+
lock (_lockObject)
19+
{
20+
using (new ChangeErrorMode(ErrorModes.FailCriticalErrors | ErrorModes.NoGpFaultErrorBox))
21+
{
22+
process = Process.Start(startInfo);
23+
process.PriorityClass = ProcessPriorityClass.Idle;
24+
}
25+
}
26+
27+
return process;
28+
}
29+
30+
// http://csharptest.net/532/using-processstart-to-capture-console-output/
31+
public static int Run(Action<string> output, Action<string> errorOutput, TextReader input, string exe, string args, string workingDirectory)
32+
{
33+
if (String.IsNullOrEmpty(exe))
34+
throw new FileNotFoundException();
35+
if (output == null)
36+
throw new ArgumentNullException("output");
37+
38+
var psi = new ProcessStartInfo
39+
{
40+
UseShellExecute = false,
41+
RedirectStandardError = true,
42+
RedirectStandardOutput = true,
43+
RedirectStandardInput = true,
44+
WindowStyle = ProcessWindowStyle.Hidden,
45+
CreateNoWindow = true,
46+
ErrorDialog = false,
47+
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory,
48+
FileName = exe,
49+
Arguments = args
50+
};
51+
52+
using (var process = Process.Start(psi))
53+
using (var mreOut = new ManualResetEvent(false))
54+
using (var mreErr = new ManualResetEvent(false))
55+
{
56+
process.EnableRaisingEvents = true;
57+
process.OutputDataReceived += (o, e) =>
58+
{
59+
// ReSharper disable once AccessToDisposedClosure
60+
if (e.Data == null)
61+
mreOut.Set();
62+
else
63+
output(e.Data);
64+
};
65+
process.BeginOutputReadLine();
66+
process.ErrorDataReceived += (o, e) =>
67+
{
68+
// ReSharper disable once AccessToDisposedClosure
69+
if (e.Data == null)
70+
mreErr.Set();
71+
else
72+
errorOutput(e.Data);
73+
};
74+
process.BeginErrorReadLine();
75+
76+
string line;
77+
while (input != null && null != (line = input.ReadLine()))
78+
process.StandardInput.WriteLine(line);
79+
80+
process.StandardInput.Close();
81+
process.WaitForExit();
82+
83+
mreOut.WaitOne();
84+
mreErr.WaitOne();
85+
86+
return process.ExitCode;
87+
}
88+
}
89+
90+
[Flags]
91+
enum ErrorModes
92+
{
93+
FailCriticalErrors = 0x1,
94+
NoGpFaultErrorBox = 0x2
95+
}
96+
97+
struct ChangeErrorMode : IDisposable
98+
{
99+
private readonly int _oldMode;
100+
101+
public ChangeErrorMode(ErrorModes mode)
102+
{
103+
_oldMode = SetErrorMode((int)mode);
104+
}
105+
106+
void IDisposable.Dispose() { SetErrorMode(_oldMode); }
107+
108+
[DllImport("kernel32.dll")]
109+
private static extern int SetErrorMode(int newMode);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)