Skip to content

Commit 07e0be4

Browse files
committed
Merge pull request #622 from onovotny/default-branch-config-updates
Default config updates to recognize more defaults
2 parents c7e70cd + 6e472fb commit 07e0be4

File tree

8 files changed

+124
-25
lines changed

8 files changed

+124
-25
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ branches:
1313
increment: Patch
1414
prevent-increment-of-merged-branch-version: true
1515
track-merge-target: false
16-
release[/-]:
16+
releases?[/-]:
1717
mode: ContinuousDelivery
1818
tag: beta
1919
increment: Patch
2020
prevent-increment-of-merged-branch-version: true
2121
track-merge-target: false
22-
feature[/-]:
22+
features?[/-]:
2323
mode: ContinuousDelivery
2424
tag: useBranchName
2525
increment: Inherit
@@ -32,7 +32,7 @@ branches:
3232
prevent-increment-of-merged-branch-version: false
3333
tag-number-pattern: '[/-](?<number>\d+)[-/]'
3434
track-merge-target: false
35-
hotfix[/-]:
35+
hotfix(es)?[/-]:
3636
mode: ContinuousDelivery
3737
tag: beta
3838
increment: Patch
@@ -44,7 +44,7 @@ branches:
4444
increment: Patch
4545
prevent-increment-of-merged-branch-version: true
4646
track-merge-target: false
47-
develop:
47+
dev(elop)?(ment)?$:
4848
mode: ContinuousDeployment
4949
tag: unstable
5050
increment: Minor

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Setup()
2424
}
2525

2626
[Test]
27-
public void CanReadDocument()
27+
public void CanReadDocumentAndMigrate()
2828
{
2929
const string text = @"
3030
assembly-versioning-scheme: MajorMinor
@@ -46,10 +46,10 @@ public void CanReadDocument()
4646
config.NextVersion.ShouldBe("2.0.0");
4747
config.TagPrefix.ShouldBe("[vV|version-]");
4848
config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
49-
config.Branches["develop"].Tag.ShouldBe("dev");
50-
config.Branches["release[/-]"].Tag.ShouldBe("rc");
51-
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
52-
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
49+
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev");
50+
config.Branches["releases?[/-]"].Tag.ShouldBe("rc");
51+
config.Branches["releases?[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
52+
config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
5353
}
5454

5555
[Test]
@@ -75,16 +75,16 @@ public void OverwritesDefaultsWithProvidedConfig()
7575
const string text = @"
7676
next-version: 2.0.0
7777
branches:
78-
develop:
78+
dev(elop)?(ment)?$:
7979
mode: ContinuousDeployment
8080
tag: dev";
8181
SetupConfigFileContent(text);
8282
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
8383

8484
config.NextVersion.ShouldBe("2.0.0");
85-
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
86-
config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode);
87-
config.Branches["develop"].Tag.ShouldBe("dev");
85+
config.Branches["dev(elop)?(ment)?$"].Increment.ShouldBe(defaultConfig.Branches["dev(elop)?(ment)?$"].Increment);
86+
config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(defaultConfig.Branches["dev(elop)?(ment)?$"].VersioningMode);
87+
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev");
8888
}
8989

9090
[Test]
@@ -117,8 +117,8 @@ public void CanReadDefaultDocument()
117117
SetupConfigFileContent(text);
118118
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
119119
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
120-
config.Branches["develop"].Tag.ShouldBe("unstable");
121-
config.Branches["release[/-]"].Tag.ShouldBe("beta");
120+
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("unstable");
121+
config.Branches["releases?[/-]"].Tag.ShouldBe("beta");
122122
config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix);
123123
config.NextVersion.ShouldBe(null);
124124
}

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
3939
Branches =
4040
{
4141
{
42-
"develop", new BranchConfig
42+
"dev(elop)?(ment)?$", new BranchConfig
4343
{
4444
VersioningMode = VersioningMode.ContinuousDeployment,
4545
Tag = "alpha"
@@ -68,8 +68,8 @@ public void CanFindParentBranchForInheritingIncrementStrategy()
6868
{
6969
Branches =
7070
{
71-
{ "develop", new BranchConfig { Increment = IncrementStrategy.Major} },
72-
{ "feature[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
71+
{ "dev(elop)?(ment)?$", new BranchConfig { Increment = IncrementStrategy.Major} },
72+
{ "features?[/-]", new BranchConfig { Increment = IncrementStrategy.Inherit} }
7373
}
7474
};
7575

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void CanChangeDevelopTagViaConfig()
5959
{
6060
Branches =
6161
{
62-
{"develop", new BranchConfig
62+
{"dev(elop)?(ment)?$", new BranchConfig
6363
{
6464
Tag = "alpha"
6565
}
@@ -75,6 +75,18 @@ public void CanChangeDevelopTagViaConfig()
7575
}
7676
}
7777

78+
[Test]
79+
public void WhenDeveloperBranchExistsDontTreatAsDevelop()
80+
{
81+
using (var fixture = new EmptyRepositoryFixture(new Config()))
82+
{
83+
fixture.Repository.MakeATaggedCommit("1.0.0");
84+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("developer"));
85+
fixture.Repository.MakeACommit();
86+
fixture.AssertFullSemver("1.0.1-developer.1+1"); // this tag should be the branch name by default, not unstable
87+
}
88+
}
89+
7890
[Test]
7991
public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
8092
{
@@ -113,7 +125,7 @@ public void CanHandleContinuousDelivery()
113125
{
114126
Branches =
115127
{
116-
{"develop", new BranchConfig
128+
{"dev(elop)?(ment)?$", new BranchConfig
117129
{
118130
VersioningMode = VersioningMode.ContinuousDelivery
119131
}

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ public void TestFeatureBranch()
111111
}
112112
}
113113

114+
[Test]
115+
public void TestFeaturesBranch()
116+
{
117+
using (var fixture = new EmptyRepositoryFixture(new Config()))
118+
{
119+
fixture.Repository.MakeATaggedCommit("1.0.0");
120+
fixture.Repository.CreateBranch("features/test");
121+
fixture.Repository.Checkout("features/test");
122+
fixture.Repository.MakeCommits(5);
123+
124+
fixture.AssertFullSemver("1.0.1-test.1+5");
125+
}
126+
}
127+
114128
[Test]
115129
public void WhenTwoFeatureBranchPointToTheSameCommit()
116130
{

src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ public void PatchLatestReleaseExample()
4242
}
4343
}
4444

45+
[Test]
46+
public void CanTakeVersionFromHotfixesBranch()
47+
{
48+
using (var fixture = new BaseGitFlowRepositoryFixture(r =>
49+
{
50+
r.MakeATaggedCommit("1.0.0");
51+
r.MakeATaggedCommit("1.1.0");
52+
r.MakeATaggedCommit("2.0.0");
53+
}))
54+
{
55+
56+
// Merge hotfix branch to support
57+
fixture.Repository.Checkout("master");
58+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("support-1.1", (Commit)fixture.Repository.Tags.Single(t => t.Name == "1.1.0").Target));
59+
fixture.AssertFullSemver("1.1.0");
60+
61+
// create hotfix branch
62+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("hotfixes/1.1.1"));
63+
fixture.AssertFullSemver("1.1.0"); // We are still on a tagged commit
64+
fixture.Repository.MakeACommit();
65+
66+
fixture.AssertFullSemver("1.1.1-beta.1+1");
67+
fixture.Repository.MakeACommit();
68+
fixture.AssertFullSemver("1.1.1-beta.1+2");
69+
}
70+
}
71+
4572
[Test]
4673
public void PatchOlderReleaseExample()
4774
{

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ public void CanTakeVersionFromReleaseBranch()
7171
}
7272
}
7373

74+
[Test]
75+
public void CanTakeVersionFromReleasesBranch()
76+
{
77+
using (var fixture = new EmptyRepositoryFixture(new Config()))
78+
{
79+
fixture.Repository.MakeATaggedCommit("1.0.3");
80+
fixture.Repository.MakeCommits(5);
81+
fixture.Repository.CreateBranch("releases/2.0.0");
82+
fixture.Repository.Checkout("releases/2.0.0");
83+
84+
fixture.AssertFullSemver("2.0.0-beta.1+0");
85+
fixture.Repository.MakeCommits(2);
86+
fixture.AssertFullSemver("2.0.0-beta.1+2");
87+
}
88+
}
89+
7490
[Test]
7591
public void ReleaseBranchWithNextVersionSetInConfig()
7692
{
@@ -95,7 +111,7 @@ public void CanTakeVersionFromReleaseBranchWithTagOverridden()
95111
{
96112
Branches =
97113
{
98-
{ "release[/-]", new BranchConfig { Tag = "rc" } }
114+
{ "releases?[/-]", new BranchConfig { Tag = "rc" } }
99115
}
100116
};
101117
using (var fixture = new EmptyRepositoryFixture(config))

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersion
22
{
3+
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
@@ -20,6 +21,8 @@ public static Config Provide(string workingDirectory, IFileSystem fileSystem, bo
2021

2122
public static void ApplyDefaultsTo(Config config)
2223
{
24+
MigrateBranches(config);
25+
2326
config.AssemblyVersioningScheme = config.AssemblyVersioningScheme ?? AssemblyVersioningScheme.MajorMinorPatch;
2427
config.TagPrefix = config.TagPrefix ?? DefaultTagPrefix;
2528
config.VersioningMode = config.VersioningMode ?? VersioningMode.ContinuousDelivery;
@@ -31,15 +34,15 @@ public static void ApplyDefaultsTo(Config config)
3134
var configBranches = config.Branches.ToList();
3235

3336
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "master"), defaultTag: string.Empty, defaultPreventIncrement: true);
34-
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "release[/-]"), defaultTag: "beta", defaultPreventIncrement: true);
35-
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "feature[/-]"), defaultIncrementStrategy: IncrementStrategy.Inherit);
37+
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "releases?[/-]"), defaultTag: "beta", defaultPreventIncrement: true);
38+
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "features?[/-]"), defaultIncrementStrategy: IncrementStrategy.Inherit);
3639
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, @"(pull|pull\-requests|pr)[/-]"),
3740
defaultTag: "PullRequest",
3841
defaultTagNumberPattern: @"[/-](?<number>\d+)[-/]",
3942
defaultIncrementStrategy: IncrementStrategy.Inherit);
40-
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix[/-]"), defaultTag: "beta");
43+
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix(es)?[/-]"), defaultTag: "beta");
4144
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "support[/-]"), defaultTag: string.Empty, defaultPreventIncrement: true);
42-
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "develop"),
45+
ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "dev(elop)?(ment)?$"),
4346
defaultTag: "unstable",
4447
defaultIncrementStrategy: IncrementStrategy.Minor,
4548
defaultVersioningMode: VersioningMode.ContinuousDeployment,
@@ -53,6 +56,33 @@ public static void ApplyDefaultsTo(Config config)
5356
}
5457
}
5558

59+
static void MigrateBranches(Config config)
60+
{
61+
// Map of current names and previous names
62+
var dict = new Dictionary<string, string[]>
63+
{
64+
{ "hotfix(es)?[/-]", new []{"hotfix[/-]"}},
65+
{ "features?[/-]", new []{"feature[/-]"}},
66+
{ "releases?[/-]", new []{"release[/-]"}},
67+
{ "dev(elop)?(ment)?$", new []{"develop"}}
68+
};
69+
70+
foreach (var mapping in dict)
71+
{
72+
foreach (var source in mapping.Value)
73+
{
74+
if (config.Branches.ContainsKey(source))
75+
{
76+
// found one, rename
77+
var bc = config.Branches[source];
78+
config.Branches.Remove(source);
79+
config.Branches[mapping.Key] = bc; // re-add with new name
80+
}
81+
}
82+
}
83+
}
84+
85+
5686
static BranchConfig GetOrCreateBranchDefaults(Config config, string branch)
5787
{
5888
if (!config.Branches.ContainsKey(branch))

0 commit comments

Comments
 (0)