Skip to content

Commit e72520f

Browse files
committed
only perform PerformPreProcessingSteps once per solution instance
fixes #87
1 parent d2a6f7e commit e72520f

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

GitVersionTask/VersionAndBranchFinder.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace GitVersionTask
22
{
3+
using System.Collections.Generic;
34
using GitVersion;
45

56
public static class VersionAndBranchFinder
67
{
7-
8+
static List<string> processedDirectories = new List<string>();
89
public static bool TryGetVersion(string directory, out SemanticVersion versionAndBranch)
910
{
1011
var gitDirectory = GitDirFinder.TreeWalkForGitDir(directory);
@@ -21,11 +22,15 @@ public static bool TryGetVersion(string directory, out SemanticVersion versionAn
2122
return false;
2223
}
2324

24-
var authentication = new Authentication();
25-
foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication))
25+
if (!processedDirectories.Contains(directory))
2626
{
27-
Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name));
28-
buildServer.PerformPreProcessingSteps(gitDirectory);
27+
processedDirectories.Add(directory);
28+
var authentication = new Authentication();
29+
foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication))
30+
{
31+
Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name));
32+
buildServer.PerformPreProcessingSteps(gitDirectory);
33+
}
2934
}
3035
versionAndBranch = VersionCache.GetVersion(gitDirectory);
3136
return true;

Tests/Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<Compile Include="BuildServers\BuildServerBaseTests.cs" />
108108
<Compile Include="BuildServers\TeamCityTests.cs" />
109109
<Compile Include="BuildServers\ContinuaCiTests.cs" />
110+
<Compile Include="VersionAndBranchFinderTests.cs" />
110111
<Compile Include="GitHubFlow\MergedBranchesWithVersionFinderTests.cs" />
111112
<Compile Include="LambdaEqualityHelperFixture.cs" />
112113
<Compile Include="GitFlow\GitFlowVersionFinderTests.cs" />

Tests/VersionAndBranchFinderTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Diagnostics;
2+
using GitVersion;
3+
using GitVersionTask;
4+
using LibGit2Sharp;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class VersionAndBranchFinderTests: Lg2sHelperBase
9+
{
10+
[Test]
11+
public void ShouldBeAbleGetVersionFromGitDir()
12+
{
13+
var repoPath = Clone(ASBMTestRepoWorkingDirPath);
14+
using (var repo = new Repository(repoPath))
15+
{
16+
// Create a pull request branch from the parent of current develop tip
17+
repo.Branches.Add("pull/1735/merge", "develop~").ForceCheckout();
18+
19+
AddOneCommitToHead(repo, "code");
20+
21+
}
22+
SemanticVersion versionAndBranch;
23+
VersionAndBranchFinder.TryGetVersion(ASBMTestRepoWorkingDirPath, out versionAndBranch);
24+
Debug.Write(versionAndBranch);
25+
}
26+
}

0 commit comments

Comments
 (0)