Skip to content

Commit 67be1f6

Browse files
committed
Current branch configuration should be set by the context
1 parent ff3cbea commit 67be1f6

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ protected SemanticVersion FindVersion(
99
GitVersionContext context,
1010
BranchType branchType)
1111
{
12-
context.CurrentBranchConfig = context.Configuration.Branches["develop"];
1312
var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);
1413

1514
if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))

GitVersionCore/GitFlow/GitFlowVersionFinder.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ public SemanticVersion FindVersion(GitVersionContext context)
1111

1212
if (context.CurrentBranch.IsHotfix())
1313
{
14-
context.CurrentBranchConfig = context.Configuration.Branches["release[/-]"];
1514
return new HotfixVersionFinder().FindVersion(context);
1615
}
1716

1817
if (context.CurrentBranch.IsRelease())
1918
{
20-
context.CurrentBranchConfig = context.Configuration.Branches["release[/-]"];
2119
return new ReleaseVersionFinder().FindVersion(context);
2220
}
2321

2422
if (context.CurrentBranch.IsDevelop())
2523
{
26-
context.CurrentBranchConfig = context.Configuration.Branches["develop"];
2724
return new DevelopVersionFinder().FindVersion(context);
2825
}
2926

GitVersionCore/GitVersionContext.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace GitVersion
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
6+
using System.Text.RegularExpressions;
57
using LibGit2Sharp;
68

79
/// <summary>
@@ -34,14 +36,16 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co
3436
{
3537
CurrentBranch = currentBranch;
3638
}
39+
40+
AssignBranchConfiguration();
3741
}
3842

3943
public Config Configuration { get; private set; }
4044
public IRepository Repository { get; private set; }
4145
public Branch CurrentBranch { get; private set; }
4246
public Commit CurrentCommit { get; private set; }
4347

44-
public BranchConfig CurrentBranchConfig { get; set; }
48+
public BranchConfig CurrentBranchConfig { get; private set; }
4549

4650
readonly bool IsContextForTrackedBranchesOnly = true;
4751

@@ -77,5 +81,23 @@ IEnumerable<Branch> GetBranchesContainingCommit(string commitSha)
7781
yield return branch;
7882
}
7983
}
84+
85+
void AssignBranchConfiguration()
86+
{
87+
var matchingBranches = Configuration.Branches.Where(b => Regex.IsMatch(CurrentBranch.Name, b.Key)).ToArray();
88+
89+
if (matchingBranches.Length == 0)
90+
{
91+
CurrentBranchConfig = new BranchConfig();
92+
}
93+
else if (matchingBranches.Length == 1)
94+
{
95+
CurrentBranchConfig = matchingBranches[0].Value;
96+
}
97+
else
98+
{
99+
throw new Exception(string.Format("Multiple branch configurations match the current branch name of ''. Matching configurations: '{0}'", string.Join(", ", matchingBranches.Select(b => b.Key))));
100+
}
101+
}
80102
}
81103
}

0 commit comments

Comments
 (0)