Skip to content

Commit 52b1603

Browse files
committed
(proj) cleanup NET472 consts
1 parent 9321194 commit 52b1603

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace GitVersion
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.InteropServices;
78
using System.Text;
89
using GitVersion.Helpers;
910
using LibGit2Sharp;
@@ -61,9 +62,9 @@ public static GitObject PeeledTarget(this Tag tag)
6162
{
6263
var target = tag.Target;
6364

64-
while (target is TagAnnotation)
65+
while (target is TagAnnotation annotation)
6566
{
66-
target = ((TagAnnotation)(target)).Target;
67+
target = annotation.Target;
6768
}
6869
return target;
6970
}
@@ -143,11 +144,11 @@ public static void DumpGraph(this IRepository repository, Action<string> writer
143144
DumpGraph(repository.Info.Path, writer, maxCommits);
144145
}
145146

146-
147147
public static void DumpGraph(string workingDirectory, Action<string> writer = null, int? maxCommits = null)
148148
{
149-
var output = new StringBuilder();
149+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return;
150150

151+
var output = new StringBuilder();
151152
try
152153
{
153154
ProcessHelper.Run(

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ public void WorkingDirectoryWithoutGitFolderCrashesWithInformativeMessage()
9494
public void WorkingDirectoryDoesNotExistCrashesWithInformativeMessage()
9595
{
9696
var workingDirectory = Path.Combine(PathHelper.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
97-
var gitVersion = Path.Combine(PathHelper.GetCurrentDirectory(), "GitVersion.exe");
97+
var executable = PathHelper.GetExecutable();
98+
9899
var output = new StringBuilder();
100+
var args = PathHelper.GetExecutableArgs(workingDirectory);
101+
99102
var exitCode = ProcessHelper.Run(
100103
s => output.AppendLine(s),
101104
s => output.AppendLine(s),
102105
null,
103-
gitVersion,
104-
workingDirectory,
106+
executable,
107+
args,
105108
PathHelper.GetCurrentDirectory());
106109

107110
exitCode.ShouldNotBe(0);

src/GitVersionExe.Tests/GitVersionHelper.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public static ExecutionResults ExecuteIn(string workingDirectory, string argumen
2929

3030
static ExecutionResults ExecuteIn(ArgumentBuilder arguments)
3131
{
32-
var gitVersion = Path.Combine(PathHelper.GetCurrentDirectory(), "GitVersion.exe");
32+
var executable = PathHelper.GetExecutable();
3333
var output = new StringBuilder();
3434

35-
Console.WriteLine("Executing: {0} {1}", gitVersion, arguments);
35+
Console.WriteLine("Executing: {0} {1}", executable, arguments);
3636
Console.WriteLine();
3737
var environmentalVariables =
3838
new[]
@@ -47,9 +47,11 @@ static ExecutionResults ExecuteIn(ArgumentBuilder arguments)
4747

4848
try
4949
{
50+
var args = PathHelper.GetExecutableArgs(arguments.ToString());
51+
5052
exitCode = ProcessHelper.Run(
5153
s => output.AppendLine(s), s => output.AppendLine(s), null,
52-
gitVersion, arguments.ToString(), arguments.WorkingDirectory,
54+
executable, args, arguments.WorkingDirectory,
5355
environmentalVariables);
5456
}
5557
catch (Exception exception)

src/GitVersionExe.Tests/Helpers/PathHelper.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Reflection;
44

@@ -9,8 +9,31 @@ public static string GetCurrentDirectory()
99
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
1010
}
1111

12+
public static string GetExecutable()
13+
{
14+
#if NET472
15+
var executable = Path.Combine(GetExeDirectory(), "GitVersion.exe");
16+
#else
17+
var executable = "dotnet";
18+
#endif
19+
return executable;
20+
}
21+
22+
public static string GetExecutableArgs(string args)
23+
{
24+
#if !NET472
25+
args = $"{Path.Combine(GetExeDirectory(), "GitVersion.dll")} {args}";
26+
#endif
27+
return args;
28+
}
29+
1230
public static string GetTempPath()
1331
{
1432
return Path.Combine(GetCurrentDirectory(), "TestRepositories", Guid.NewGuid().ToString());
1533
}
16-
}
34+
35+
private static string GetExeDirectory()
36+
{
37+
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)?.Replace("GitVersionExe.Tests", "GitVersionExe");
38+
}
39+
}

src/GitVersionExe/Program.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ static int VerifyArgumentsAndRun()
7777
}
7878

7979
ConfigureLogging(arguments);
80-
#if NET472
8180
if (arguments.Diag)
8281
{
8382
Logger.WriteInfo("Dumping commit graph: ");
8483
LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
8584
}
86-
#endif
8785
if (!Directory.Exists(arguments.TargetPath))
8886
{
8987
Logger.WriteWarning($"The working directory '{arguments.TargetPath}' does not exist.");
@@ -131,9 +129,7 @@ static int VerifyArgumentsAndRun()
131129

132130
try
133131
{
134-
#if NET472
135132
LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
136-
#endif
137133
}
138134
catch (Exception dumpGraphException)
139135
{
@@ -173,10 +169,7 @@ static void ConfigureLogging(Arguments arguments)
173169
var logFile = new FileInfo(logFileFullPath);
174170

175171
// NOTE: logFile.Directory will be null if the path is i.e. C:\logfile.log. @asbjornu
176-
if (logFile.Directory != null)
177-
{
178-
logFile.Directory.Create();
179-
}
172+
logFile.Directory?.Create();
180173

181174
using (logFile.CreateText())
182175
{

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
6767
{
6868
assemblyInfoUpdater.Update();
6969
}
70-
var execRun = false;
71-
var msbuildRun = false;
72-
#if NET472
73-
execRun = RunExecCommandIfNeeded(arguments, targetPath, variables);
74-
msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables);
75-
#endif
70+
71+
var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables);
72+
var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables);
7673

7774
if (!execRun && !msbuildRun)
7875
{
@@ -87,11 +84,8 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
8784
}
8885
}
8986
}
90-
#if NET472
9187
static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionVariables variables)
9288
{
93-
94-
9589
if (string.IsNullOrEmpty(args.Proj)) return false;
9690

9791
Logger.WriteInfo($"Launching build tool {BuildTool} \"{args.Proj}\" {args.ProjArgs}");
@@ -105,8 +99,6 @@ static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionV
10599

106100
return true;
107101
}
108-
109-
110102
static bool RunExecCommandIfNeeded(Arguments args, string workingDirectory, VersionVariables variables)
111103
{
112104
if (string.IsNullOrEmpty(args.Exec)) return false;
@@ -122,7 +114,6 @@ static bool RunExecCommandIfNeeded(Arguments args, string workingDirectory, Vers
122114

123115
return true;
124116
}
125-
#endif
126117
static KeyValuePair<string, string>[] GetEnvironmentalVariables(VersionVariables variables)
127118
{
128119
return variables

0 commit comments

Comments
 (0)