Skip to content

Commit e4c3535

Browse files
committed
Allow develop branch name to be configured. Fixes GitTools#292
1 parent 9264a60 commit e4c3535

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

GitVersionCore/Configuration/Config.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public Config()
88
{
99
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
1010
DevelopBranchTag = "unstable";
11+
DevelopBranchName = "develop";
1112
ReleaseBranchTag = "beta";
1213
TagPrefix = "v";
1314
}
@@ -17,6 +18,9 @@ public Config()
1718
[YamlAlias("develop-branch-tag")]
1819
public string DevelopBranchTag { get; set; }
1920

21+
[YamlAlias("develop-branch-name")]
22+
public string DevelopBranchName { get; set; }
23+
2024
[YamlAlias("release-branch-tag")]
2125
public string ReleaseBranchTag { get; set; }
2226

GitVersionCore/GitFlow/BranchClassifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public static bool IsRelease(this Branch branch)
1515
return branch.Name.StartsWith("release-") || branch.Name.StartsWith("release/");
1616
}
1717

18-
public static bool IsDevelop(this Branch branch)
18+
public static bool IsDevelop(this Branch branch, Config config)
1919
{
20-
return branch.Name == "develop";
20+
return branch.Name == config.DevelopBranchName;
2121
}
2222

2323
public static bool IsMaster(this Branch branch)

GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ protected SemanticVersion FindVersion(
99
GitVersionContext context,
1010
BranchType branchType)
1111
{
12-
var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);
12+
var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType, context.Configuration);
1313

14-
if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))
14+
if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch, context.Configuration))
1515
{
1616
var developVersionFinder = new DevelopVersionFinder();
1717
return developVersionFinder.FindVersion(context);
@@ -54,10 +54,10 @@ int NumberOfCommitsOnBranchSinceCommit(GitVersionContext context, Commit commit)
5454
.Count();
5555
}
5656

57-
Commit FindCommonAncestorWithDevelop(IRepository repo, Branch branch, BranchType branchType)
57+
Commit FindCommonAncestorWithDevelop(IRepository repo, Branch branch, BranchType branchType, Config configuration)
5858
{
5959
var ancestor = repo.Commits.FindMergeBase(
60-
repo.FindBranch("develop").Tip,
60+
repo.FindBranch(configuration.DevelopBranchName).Tip,
6161
branch.Tip);
6262

6363
if (ancestor != null)
@@ -71,12 +71,12 @@ Commit FindCommonAncestorWithDevelop(IRepository repo, Branch branch, BranchType
7171
, branchType, branch.Name));
7272
}
7373

74-
public bool IsThereAnyCommitOnTheBranch(IRepository repo, Branch branch)
74+
public bool IsThereAnyCommitOnTheBranch(IRepository repo, Branch branch, Config config)
7575
{
7676
var filter = new CommitFilter
7777
{
7878
Since = branch,
79-
Until = repo.FindBranch("develop")
79+
Until = repo.FindBranch(config.DevelopBranchName)
8080
};
8181

8282
var commits = repo.Commits.QueryBy(filter);

GitVersionCore/GitFlow/GitFlowVersionFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
1919
return new ReleaseVersionFinder().FindVersion(context);
2020
}
2121

22-
if (context.CurrentBranch.IsDevelop())
22+
if (context.CurrentBranch.IsDevelop(context.Configuration))
2323
{
2424
return new DevelopVersionFinder().FindVersion(context);
2525
}

GitVersionCore/GitVersionFinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
1010
Logger.WriteInfo("Running against branch: " + context.CurrentBranch.Name);
1111
EnsureMainTopologyConstraints(context);
1212

13-
if (ShouldGitHubFlowVersioningSchemeApply(context.Repository))
13+
if (ShouldGitHubFlowVersioningSchemeApply(context.Repository, context.Configuration))
1414
{
1515
Logger.WriteInfo("GitHubFlow version strategy will be used");
1616
return new GitHubFlowVersionFinder().FindVersion(context);
@@ -20,9 +20,9 @@ public SemanticVersion FindVersion(GitVersionContext context)
2020
return new GitFlowVersionFinder().FindVersion(context);
2121
}
2222

23-
static bool ShouldGitHubFlowVersioningSchemeApply(IRepository repo)
23+
static bool ShouldGitHubFlowVersioningSchemeApply(IRepository repo, Config configuration)
2424
{
25-
return repo.FindBranch("develop") == null;
25+
return repo.FindBranch(configuration.DevelopBranchName) == null;
2626
}
2727

2828
void EnsureMainTopologyConstraints(GitVersionContext context)

GitVersionCore/OutputVariables/VariableProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static class VariableProvider
3434
public static Dictionary<string, string> GetVariablesFor(SemanticVersion semanticVersion, Config configuration)
3535
{
3636
var bmd = semanticVersion.BuildMetaData;
37-
var formatter = bmd.Branch == "develop" ? new CiFeedFormatter() : null;
37+
var formatter = bmd.Branch == configuration.DevelopBranchName ? new CiFeedFormatter() : null;
3838

3939
var variables = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
4040
{

GitVersionTask.Tests/BranchClassifierTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public void IsSupport()
3535
[Test]
3636
public void IsDevelop()
3737
{
38-
Assert.IsTrue(new MockBranch("develop").IsDevelop());
39-
Assert.IsTrue(new MockBranch("Develop").IsDevelop());
40-
Assert.IsFalse(new MockBranch("hotfix1").IsDevelop());
38+
Assert.IsTrue(new MockBranch("develop").IsDevelop(new Config()));
39+
Assert.IsTrue(new MockBranch("Develop").IsDevelop(new Config()));
40+
Assert.IsFalse(new MockBranch("hotfix1").IsDevelop(new Config()));
4141
}
4242
[Test]
4343
public void IsMaster()

0 commit comments

Comments
 (0)