Skip to content

Commit bc7a841

Browse files
committed
Bump develop when release branch is created
- Fixed an commit counting bug - Based on discussion at #632 - Fixes #695 - Updated related docs
1 parent fd34b7e commit bc7a841

29 files changed

+280
-120
lines changed

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ The global configuration options are:
4646
- **`sha:`** A sequence of SHAs to be excluded from the version calculations. Useful when there is a rogue commit in history yielding a bad version.
4747
- **`commits-before:`** Allows to setup an exclusion range. Effectively any commit < `commits-before` will be ignored.
4848

49+
- **`is-develop:`** Indicates this branch config represents develop in GitFlow
50+
51+
**`is-release-branch:`** Indicates this branch config represents a release branch in GitFlow
52+
4953
## Branch configuration
5054

5155
Then we have branch specific configuration, which looks something like this:
Loading
Loading

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,56 @@ branches:
1616
increment: Patch
1717
prevent-increment-of-merged-branch-version: true
1818
track-merge-target: false
19+
is-develop: false
20+
is-release-branch: false
1921
releases?[/-]:
2022
mode: ContinuousDelivery
2123
tag: beta
2224
increment: Patch
2325
prevent-increment-of-merged-branch-version: true
2426
track-merge-target: false
27+
is-develop: false
28+
is-release-branch: true
2529
features?[/-]:
2630
mode: ContinuousDelivery
2731
tag: useBranchName
2832
increment: Inherit
2933
prevent-increment-of-merged-branch-version: false
3034
track-merge-target: false
35+
is-develop: false
36+
is-release-branch: false
3137
(pull|pull\-requests|pr)[/-]:
3238
mode: ContinuousDelivery
3339
tag: PullRequest
3440
increment: Inherit
3541
prevent-increment-of-merged-branch-version: false
3642
tag-number-pattern: '[/-](?<number>\d+)[-/]'
3743
track-merge-target: false
44+
is-develop: false
45+
is-release-branch: false
3846
hotfix(es)?[/-]:
3947
mode: ContinuousDelivery
4048
tag: beta
4149
increment: Patch
4250
prevent-increment-of-merged-branch-version: false
4351
track-merge-target: false
52+
is-develop: false
53+
is-release-branch: false
4454
support[/-]:
4555
mode: ContinuousDelivery
4656
tag: ''
4757
increment: Patch
4858
prevent-increment-of-merged-branch-version: true
4959
track-merge-target: false
60+
is-develop: false
61+
is-release-branch: false
5062
dev(elop)?(ment)?$:
5163
mode: ContinuousDeployment
5264
tag: unstable
5365
increment: Minor
5466
prevent-increment-of-merged-branch-version: false
5567
track-merge-target: true
68+
is-develop: true
69+
is-release-branch: false
5670
ignore:
5771
sha: []

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void CanProvideConfigForNewBranch()
112112
tag: bugfix";
113113
SetupConfigFileContent(text);
114114
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
115-
115+
116116
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
117117
}
118118

@@ -145,7 +145,7 @@ public void NextVersionCanHavePatch()
145145

146146
config.NextVersion.ShouldBe("2.12.654651698");
147147
}
148-
148+
149149
[Test]
150150
[Category("NoMono")]
151151
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
@@ -235,10 +235,10 @@ public void WarnOnExistingGitVersionConfigYamlFile()
235235

236236
var s = string.Empty;
237237
Action<string> action = info => { s = info; };
238-
Logger.SetLoggers(action, action, action);
239-
240-
ConfigurationProvider.Provide(repoPath, fileSystem);
241-
238+
using (Logger.AddLoggersTemporarily(action, action, action))
239+
{
240+
ConfigurationProvider.Provide(repoPath, fileSystem);
241+
}
242242
s.Contains("'GitVersionConfig.yaml' is deprecated, use 'GitVersion.yml' instead.").ShouldBe(true);
243243
}
244244

@@ -249,10 +249,10 @@ public void NoWarnOnGitVersionYmlFile()
249249

250250
var s = string.Empty;
251251
Action<string> action = info => { s = info; };
252-
Logger.SetLoggers(action, action, action);
253-
254-
ConfigurationProvider.Provide(repoPath, fileSystem);
255-
252+
using (Logger.AddLoggersTemporarily(action, action, action))
253+
{
254+
ConfigurationProvider.Provide(repoPath, fileSystem);
255+
}
256256
s.Length.ShouldBe(0);
257257
}
258258

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFix
147147
Action<string> infoLogger = s =>
148148
{
149149
infoBuilder.AppendLine(s);
150-
Console.WriteLine(s);
151150
};
152151
executeCore = executeCore ?? new ExecuteCore(fileSystem);
153152

154-
Logger.SetLoggers(infoLogger, Console.WriteLine, Console.WriteLine);
155-
153+
using (Logger.AddLoggersTemporarily(infoLogger, s => {}, s => { }))
156154
using (var fixture = new EmptyRepositoryFixture())
157155
{
158156
fixture.Repository.MakeACommit();

src/GitVersionCore.Tests/GitToolsTestingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static SemanticVersion ExecuteGitVersion(GitVersionContext context)
7070
/// </summary>
7171
public static void InitialiseRepo(this RemoteRepositoryFixture fixture)
7272
{
73-
// TODO !!new GitPreparer(null, null, new Authentication(), false, fixture.LocalRepositoryFixture.RepositoryPath).Initialise(true, null);
73+
new GitPreparer(null, null, new Authentication(), false, fixture.LocalRepositoryFixture.RepositoryPath).Initialise(true, null);
7474
}
7575
}
7676
}

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ public void CanChangeDevelopTagViaConfig()
6161
{
6262
Branches =
6363
{
64-
{"dev(elop)?(ment)?$", new BranchConfig
6564
{
66-
Tag = "alpha"
67-
}
65+
"dev(elop)?(ment)?$", new BranchConfig
66+
{
67+
Tag = "alpha"
68+
}
6869
}
6970
}
7071
};
@@ -116,7 +117,7 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel
116117

117118
fixture.Repository.Checkout("develop");
118119
fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow());
119-
fixture.AssertFullSemver("2.1.0-unstable.0");
120+
fixture.AssertFullSemver("2.1.0-unstable.2");
120121
}
121122
}
122123

@@ -157,4 +158,27 @@ public void WhenDevelopBranchedFromMasterDetachedHead_MinorIsIncreased()
157158
fixture.AssertFullSemver("1.1.0-unstable.1");
158159
}
159160
}
161+
162+
[Test]
163+
public void InheritVersionFromReleaseBranch()
164+
{
165+
using (var fixture = new EmptyRepositoryFixture())
166+
{
167+
fixture.MakeATaggedCommit("1.0.0");
168+
fixture.BranchTo("develop");
169+
fixture.MakeACommit();
170+
fixture.BranchTo("release/2.0.0");
171+
fixture.MakeACommit();
172+
fixture.MakeACommit();
173+
fixture.Checkout("develop");
174+
fixture.AssertFullSemver("2.1.0-unstable.0");
175+
fixture.MakeACommit();
176+
fixture.AssertFullSemver("2.1.0-unstable.1");
177+
fixture.MergeNoFF("release/2.0.0");
178+
fixture.AssertFullSemver("2.1.0-unstable.4");
179+
fixture.BranchTo("feature/MyFeature");
180+
fixture.MakeACommit();
181+
fixture.AssertFullSemver("2.1.0-MyFeature.1+1");
182+
}
183+
}
160184
}

src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void GitFlowMinorRelease()
130130
// Make another commit on develop
131131
fixture.Checkout("develop");
132132
fixture.MakeACommit();
133-
fixture.AssertFullSemver("1.3.0-unstable.2");
133+
fixture.AssertFullSemver("1.4.0-unstable.1");
134134

135135
// Make a commit to release-1.3.0
136136
fixture.Checkout("release/1.3.0");
@@ -159,7 +159,7 @@ public void GitFlowMinorRelease()
159159

160160
// Not 0 for commit count as we can't know the increment rules of the merged branch
161161
fixture.Checkout("develop");
162-
fixture.AssertFullSemver("1.4.0-unstable.2");
162+
fixture.AssertFullSemver("1.4.0-unstable.4");
163163
}
164164
}
165165

@@ -186,7 +186,7 @@ public void GitFlowMajorRelease()
186186
// Make another commit on develop
187187
fixture.Checkout("develop");
188188
fixture.MakeACommit();
189-
fixture.AssertFullSemver("1.4.0-unstable.2");
189+
fixture.AssertFullSemver("2.1.0-unstable.1");
190190

191191
// Make a commit to release-2.0.0
192192
fixture.Checkout("release/2.0.0");
@@ -216,7 +216,7 @@ public void GitFlowMajorRelease()
216216

217217
// Not 0 for commit count as we can't know the increment rules of the merged branch
218218
fixture.Checkout("develop");
219-
fixture.AssertFullSemver("2.1.0-unstable.2");
219+
fixture.AssertFullSemver("2.1.0-unstable.4");
220220
}
221221
}
222222

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void NoMergeBacksToDevelopInCaseThereAreChangesInReleaseBranch()
4848
// Merge to develop
4949
fixture.Repository.Checkout("develop");
5050
fixture.Repository.MergeNoFF("release/1.0.0");
51-
fixture.AssertFullSemver("1.1.0-unstable.1");
51+
fixture.AssertFullSemver("1.1.0-unstable.2");
5252

5353
fixture.Repository.MakeACommit();
5454
fixture.Repository.Branches.Remove(releaseBranch);
@@ -226,7 +226,7 @@ public void WhenReleaseBranchIsMergedIntoDevelopHighestVersionIsTakenWithIt()
226226
fixture.Repository.Checkout("develop");
227227
fixture.Repository.MergeNoFF("release-1.0.0", Generate.SignatureNow());
228228

229-
fixture.AssertFullSemver("2.1.0-unstable.5");
229+
fixture.AssertFullSemver("2.1.0-unstable.6");
230230
}
231231
}
232232

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using NUnit.Framework;
22
using System;
33
using GitVersion;
4+
using Shouldly;
5+
46
namespace GitVersionCore.Tests
57
{
68
[TestFixture]
@@ -15,25 +17,22 @@ public void LoggerObscuresPassword(string protocol)
1517
const string password = "password";
1618
var s = string.Empty;
1719
Action<string> action = info => { s = info; };
18-
Logger.SetLoggers(action, action, action);
19-
20-
Logger.WriteInfo(string.Format("{0}://{1}:{2}@workspace.visualstudio.com/DefaultCollection/_git/CAS",protocol,username,password));
20+
using (Logger.AddLoggersTemporarily(action, action, action))
21+
Logger.WriteInfo(string.Format("{0}://{1}:{2}@workspace.visualstudio.com/DefaultCollection/_git/CAS",protocol,username,password));
2122

22-
Assert.IsFalse(s.Contains(password));
23+
s.Contains(password).ShouldBe(false);
2324
}
2425

2526
[Test]
2627
public void UsernameWithoutPassword()
2728
{
2829
var s = string.Empty;
2930
Action<string> action = info => { s = info; };
30-
Logger.SetLoggers(action, action, action);
31-
3231
const string repoUrl = "http://[email protected]/DefaultCollection/_git/CAS";
33-
Logger.WriteInfo(repoUrl);
32+
using (Logger.AddLoggersTemporarily(action, action, action))
33+
Logger.WriteInfo(repoUrl);
3434

35-
Assert.IsTrue(s.Contains(repoUrl));
35+
s.Contains(repoUrl).ShouldBe(true);
3636
}
37-
3837
}
3938
}

src/GitVersionCore.Tests/ModuleInitializer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.Diagnostics;
2-
using GitVersion;
1+
using GitVersion;
2+
using System;
33

44
/// <summary>
55
/// Used by the ModuleInit. All code inside the Initialize method is ran as soon as the assembly is loaded.
@@ -11,6 +11,9 @@ public static class ModuleInitializer
1111
/// </summary>
1212
public static void Initialize()
1313
{
14-
Logger.SetLoggers(s => Trace.WriteLine(s), s => Trace.WriteLine(s), s => Trace.WriteLine(s));
14+
Logger.SetLoggers(
15+
s => Console.WriteLine(s),
16+
s => Console.WriteLine(s),
17+
s => Console.WriteLine(s));
1518
}
1619
}

src/GitVersionCore.Tests/TestEffectiveConfiguration.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ public TestEffectiveConfiguration(
2626
int legacySemVerPadding = 4,
2727
int buildMetaDataPadding = 4,
2828
int commitsSinceVersionSourcePadding = 4,
29-
IEnumerable<IVersionFilter> versionFilters = null
30-
) :
29+
IEnumerable<IVersionFilter> versionFilters = null,
30+
bool isDevelop = false,
31+
bool isRelease = false) :
3132
base(assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch,
3233
branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag,
3334
trackMergeTarget,
3435
majorMessage, minorMessage, patchMessage,
3536
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
36-
versionFilters ?? Enumerable.Empty<IVersionFilter>())
37+
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
38+
isDevelop, isRelease)
3739
{
3840
}
3941
}

src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using GitVersion;
33
using GitVersion.VersionCalculation.BaseVersionCalculators;
44
using GitVersion.VersionFilters;
5-
using LibGit2Sharp;
65
using NUnit.Framework;
76
using Shouldly;
87

@@ -14,7 +13,6 @@ public class MinDateVersionFilterTests
1413
[Test]
1514
public void VerifyNullGuard()
1615
{
17-
var commit = new MockCommit();
1816
var dummy = DateTimeOffset.UtcNow.AddSeconds(1.0);
1917
var sut = new MinDateVersionFilter(dummy);
2018

@@ -51,8 +49,7 @@ public void WhenShaMismatchShouldNotExclude()
5149
[Test]
5250
public void ExcludeShouldAcceptVersionWithNullCommit()
5351
{
54-
Commit nullCommit = null;
55-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty);
52+
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
5653
var futureDate = DateTimeOffset.UtcNow.AddYears(1);
5754
var sut = new MinDateVersionFilter(futureDate);
5855

src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using GitVersion;
33
using GitVersion.VersionCalculation.BaseVersionCalculators;
44
using GitVersion.VersionFilters;
5-
using LibGit2Sharp;
65
using NUnit.Framework;
76
using Shouldly;
87

@@ -54,8 +53,7 @@ public void WhenShaMismatchShouldNotExclude()
5453
[Test]
5554
public void ExcludeShouldAcceptVersionWithNullCommit()
5655
{
57-
Commit nullCommit = null;
58-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty);
56+
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
5957
var sut = new ShaVersionFilter(new[] { "mismatched" });
6058

6159
string reason;

src/GitVersionCore/Configuration/BranchConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public BranchConfig(BranchConfig branchConfiguration)
1717
TagNumberPattern = branchConfiguration.TagNumberPattern;
1818
TrackMergeTarget = branchConfiguration.TrackMergeTarget;
1919
CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing;
20+
IsDevelop = branchConfiguration.IsDevelop;
21+
IsReleaseBranch = branchConfiguration.IsReleaseBranch;
2022
}
2123

2224
[YamlMember(Alias = "mode")]
@@ -42,5 +44,11 @@ public BranchConfig(BranchConfig branchConfiguration)
4244

4345
[YamlMember(Alias = "commit-message-incrementing")]
4446
public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; }
47+
48+
[YamlMember(Alias = "is-develop")]
49+
public bool? IsDevelop { get; set; }
50+
51+
[YamlMember(Alias = "is-release-branch")]
52+
public bool? IsReleaseBranch { get; set; }
4553
}
4654
}

0 commit comments

Comments
 (0)