Skip to content

Commit afd64db

Browse files
committed
Introduced executecore in core which both exe and task can use
1 parent 1225890 commit afd64db

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

GitVersionCore/ExecuteCore.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using GitVersion.Helpers;
5+
6+
public static class ExecuteCore
7+
{
8+
public static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId)
9+
{
10+
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, workingDirectory);
11+
gitPreparer.InitialiseDynamicRepositoryIfNeeded();
12+
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
13+
var projectRoot = gitPreparer.GetProjectRootDirectory();
14+
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
15+
{
16+
// TODO Link to wiki article
17+
throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
18+
}
19+
20+
foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication))
21+
{
22+
buildServer.PerformPreProcessingSteps(dotGitDirectory, noFetch);
23+
}
24+
VersionVariables variables;
25+
var versionFinder = new GitVersionFinder();
26+
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem);
27+
28+
using (var repo = RepositoryLoader.GetRepo(dotGitDirectory))
29+
{
30+
var gitVersionContext = new GitVersionContext(repo, configuration, commitId: commitId);
31+
var semanticVersion = versionFinder.FindVersion(gitVersionContext);
32+
var config = gitVersionContext.Configuration;
33+
variables = VariableProvider.GetVariablesFor(semanticVersion, config.AssemblyVersioningScheme, config.VersioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged);
34+
}
35+
36+
return variables;
37+
}
38+
}
39+
}

GitVersionExe/GitPreparer.cs renamed to GitVersionCore/GitPreparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GitVersion
1+
namespace GitVersion
22
{
33
using System;
44
using System.IO;

GitVersionCore/GitVersionCore.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
<Compile Include="Configuration\LegacyConfigNotifier.cs" />
8282
<Compile Include="Configuration\OldConfigurationException.cs" />
8383
<Compile Include="EffectiveConfiguration.cs" />
84+
<Compile Include="ExecuteCore.cs" />
85+
<Compile Include="GitPreparer.cs" />
8486
<Compile Include="Helpers\FileSystem.cs" />
8587
<Compile Include="Helpers\IFileSystem.cs" />
8688
<Compile Include="Helpers\ProcessHelper.cs" />

GitVersionExe/GitVersionExe.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
<Compile Include="ArgumentParser.cs" />
5757
<Compile Include="Arguments.cs" />
5858
<Compile Include="ExtensionMethods.cs" />
59-
<Compile Include="GitPreparer.cs" />
6059
<Compile Include="HelpWriter.cs" />
6160
<Compile Include="Program.cs" />
6261
<Compile Include="AssemblyInfo.cs" />

GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
1818
var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation;
1919
var targetBranch = arguments.TargetBranch;
2020
var commitId = arguments.CommitId;
21-
var variables = ExecuteGitVersion(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId);
21+
var variables = ExecuteCore.ExecuteGitVersion(fileSystem, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId);
2222

2323
if (arguments.Output == OutputType.BuildServer)
2424
{
@@ -65,37 +65,6 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
6565
}
6666
}
6767

68-
static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId)
69-
{
70-
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, workingDirectory);
71-
gitPreparer.InitialiseDynamicRepositoryIfNeeded();
72-
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
73-
var projectRoot = gitPreparer.GetProjectRootDirectory();
74-
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
75-
{
76-
// TODO Link to wiki article
77-
throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
78-
}
79-
80-
foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication))
81-
{
82-
buildServer.PerformPreProcessingSteps(dotGitDirectory, noFetch);
83-
}
84-
VersionVariables variables;
85-
var versionFinder = new GitVersionFinder();
86-
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem);
87-
88-
using (var repo = RepositoryLoader.GetRepo(dotGitDirectory))
89-
{
90-
var gitVersionContext = new GitVersionContext(repo, configuration, commitId: commitId);
91-
var semanticVersion = versionFinder.FindVersion(gitVersionContext);
92-
var config = gitVersionContext.Configuration;
93-
variables = VariableProvider.GetVariablesFor(semanticVersion, config.AssemblyVersioningScheme, config.VersioningMode, config.ContinuousDeploymentFallbackTag, gitVersionContext.IsCurrentCommitTagged);
94-
}
95-
96-
return variables;
97-
}
98-
9968
static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionVariables variables)
10069
{
10170
if (string.IsNullOrEmpty(args.Proj)) return false;

0 commit comments

Comments
 (0)