Skip to content

Commit 9fd376c

Browse files
committed
take versions from branch names only when they are release (remove config flag and make it the default behavior); include remote release branches
1 parent ccd0330 commit 9fd376c

19 files changed

+253
-132
lines changed

docs/configuration.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
179179
2015-10-23T12:23:15`) to setup an exclusion range. Effectively any commit before
180180
`commits-before` will be ignored.
181181
182-
#### non-release-branches
183-
By default all branches that have a semantic version in their name will be used
184-
to calculate the version. This can be restricted to [release branches](#is-release-branch)
185-
by setting this flag to `true`. Default is `false`.
186-
187182
## Branch configuration
188183
Then we have branch specific configuration, which looks something like this:
189184

src/GitVersionCore.Tests/Configuration/IgnoreConfigTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using GitVersion;
44
using NUnit.Framework;
@@ -17,7 +17,6 @@ public void CanDeserialize()
1717
ignore:
1818
sha: [b6c0c9fda88830ebcd563e500a5a7da5a1658e98]
1919
commits-before: 2015-10-23T12:23:15
20-
non-release-branches: true
2120
";
2221

2322
using (var reader = new StringReader(yaml))
@@ -28,7 +27,6 @@ public void CanDeserialize()
2827
config.Ignore.SHAs.ShouldNotBeEmpty();
2928
config.Ignore.SHAs.ShouldBe(new[] { "b6c0c9fda88830ebcd563e500a5a7da5a1658e98" });
3029
config.Ignore.Before.ShouldBe(DateTimeOffset.Parse("2015-10-23T12:23:15"));
31-
config.Ignore.NonReleaseBranches.ShouldBe(true);
3230
}
3331
}
3432

@@ -66,7 +64,6 @@ public void WhenNotInConfigShouldHaveDefaults()
6664
config.Ignore.ShouldNotBeNull();
6765
config.Ignore.SHAs.ShouldBeEmpty();
6866
config.Ignore.Before.ShouldBeNull();
69-
config.Ignore.NonReleaseBranches.ShouldBeNull();
7067
}
7168
}
7269

@@ -84,4 +81,4 @@ public void WhenBadDateFormatShouldFail()
8481
}
8582
}
8683
}
87-
}
84+
}

src/GitVersionCore.Tests/IntegrationTests/OtherBranchScenarios.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using GitVersionCore.Tests;
33
using LibGit2Sharp;
44
using NUnit.Framework;
@@ -15,10 +15,10 @@ public void CanTakeVersionFromReleaseBranch()
1515
const string TaggedVersion = "1.0.3";
1616
fixture.Repository.MakeATaggedCommit(TaggedVersion);
1717
fixture.Repository.MakeCommits(5);
18-
fixture.Repository.CreateBranch("alpha-2.0.0");
19-
Commands.Checkout(fixture.Repository, "alpha-2.0.0");
18+
fixture.Repository.CreateBranch("release/beta-2.0.0");
19+
Commands.Checkout(fixture.Repository, "release/beta-2.0.0");
2020

21-
fixture.AssertFullSemver("2.0.0-alpha.1+0");
21+
fixture.AssertFullSemver("2.0.0-beta.1+0");
2222
}
2323
}
2424

@@ -57,4 +57,4 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
5757
version.SemVer.ShouldBe("1.0.0-alpha.1");
5858
}
5959
}
60-
}
60+
}
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
namespace GitVersionCore.Tests.IntegrationTests
22
{
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
using GitTools.Testing;
67

78
using GitVersion;
89

910
using GitVersionCore.Tests;
11+
12+
using LibGit2Sharp;
13+
1014
using NUnit.Framework;
1115

1216
[TestFixture]
1317
public class VersionInCurrentBranchNameScenarios : TestBase
1418
{
1519
[Test]
16-
public void TakesVersionFromNameOfAnyBranchByDefault()
20+
public void TakesVersionFromNameOfReleaseBranch()
1721
{
1822
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
1923
{
20-
fixture.BranchTo("feature/upgrade-power-level-to-9000.0.1");
24+
fixture.BranchTo("release/2.0.0");
2125

22-
fixture.AssertFullSemver("9000.0.1-upgrade-power-level-to.1+0");
26+
fixture.AssertFullSemver("2.0.0-beta.1+0");
2327
}
2428
}
2529

2630
[Test]
27-
public void TakesVersionOnlyFromNameOfReleaseBranchByConfig()
31+
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
2832
{
29-
var config = new Config { Ignore = new IgnoreConfig { NonReleaseBranches = true } };
30-
3133
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
3234
{
3335
fixture.BranchTo("feature/upgrade-power-level-to-9000.0.1");
3436

35-
fixture.AssertFullSemver(config, "1.1.0-upgrade-power-level-to-9000-0-1.1+1");
37+
fixture.AssertFullSemver("1.1.0-upgrade-power-level-to-9000-0-1.1+1");
3638
}
3739
}
3840

@@ -41,7 +43,6 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
4143
{
4244
var config = new Config
4345
{
44-
Ignore = new IgnoreConfig { NonReleaseBranches = true },
4546
Branches = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }
4647
};
4748

@@ -52,5 +53,20 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
5253
fixture.AssertFullSemver(config, "2.0.0+1");
5354
}
5455
}
56+
57+
[Test]
58+
public void TakesVersionFromNameOfRemoteReleaseBranch()
59+
{
60+
using (var fixture = new RemoteRepositoryFixture())
61+
{
62+
fixture.BranchTo("release/2.0.0");
63+
fixture.MakeACommit();
64+
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);
65+
66+
fixture.LocalRepositoryFixture.Checkout("origin/release/2.0.0");
67+
68+
fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-beta.1+1");
69+
}
70+
}
5571
}
5672
}

src/GitVersionCore.Tests/IntegrationTests/VersionsInMergedBranchNamesScenarios.cs renamed to src/GitVersionCore.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
namespace GitVersionCore.Tests.IntegrationTests
22
{
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
using GitTools.Testing;
67

78
using GitVersion;
89

910
using GitVersionCore.Tests;
1011

12+
using LibGit2Sharp;
13+
1114
using NUnit.Framework;
1215

1316
[TestFixture]
14-
public class VersionsInMergedBranchNamesScenarios : TestBase
17+
public class VersionInMergedBranchNameScenarios : TestBase
1518
{
1619
[Test]
17-
public void TakesVersionFromNameOfAnyBranchByDefault()
20+
public void TakesVersionFromNameOfReleaseBranch()
1821
{
1922
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
2023
{
21-
fixture.CreateAndMergeBranchIntoDevelop("feature/upgrade-power-level-to-9000.0.1");
24+
fixture.CreateAndMergeBranchIntoDevelop("release/2.0.0");
2225

23-
fixture.AssertFullSemver("9000.1.0-alpha.0");
26+
fixture.AssertFullSemver("2.1.0-alpha.2");
2427
}
2528
}
2629

2730
[Test]
28-
public void TakesVersionOnlyFromNameOfReleaseBranchByConfig()
31+
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
2932
{
30-
var config = new Config { Ignore = new IgnoreConfig { NonReleaseBranches = true } };
31-
3233
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
3334
{
3435
fixture.CreateAndMergeBranchIntoDevelop("pull-request/improved-by-upgrading-some-lib-to-4.5.6");
35-
fixture.CreateAndMergeBranchIntoDevelop("release/2.0.0");
3636
fixture.CreateAndMergeBranchIntoDevelop("hotfix/downgrade-some-lib-to-3.2.1-to-avoid-breaking-changes");
3737

38-
fixture.AssertFullSemver(config, "2.1.0-alpha.4");
38+
fixture.AssertFullSemver("1.1.0-alpha.5");
3939
}
4040
}
4141

@@ -44,7 +44,6 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
4444
{
4545
var config = new Config
4646
{
47-
Ignore = new IgnoreConfig { NonReleaseBranches = true },
4847
Branches = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }
4948
};
5049

@@ -55,6 +54,21 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
5554
fixture.AssertFullSemver(config, "2.1.0-alpha.2");
5655
}
5756
}
57+
58+
[Test]
59+
public void TakesVersionFromNameOfRemoteReleaseBranch()
60+
{
61+
using (var fixture = new RemoteRepositoryFixture())
62+
{
63+
fixture.BranchTo("release/2.0.0");
64+
fixture.MakeACommit();
65+
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);
66+
67+
fixture.LocalRepositoryFixture.MergeNoFF("origin/release/2.0.0");
68+
69+
fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0+0");
70+
}
71+
}
5872
}
5973

6074
internal static class BaseGitFlowRepositoryFixtureExtensions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace GitVersionCore.Tests.Mocks
2+
{
3+
using System.Collections.Generic;
4+
5+
using LibGit2Sharp;
6+
7+
public class MockNetwork : Network
8+
{
9+
public MockNetwork(IEnumerable<MockRemote> mockRemotes)
10+
{
11+
Remotes = new MockRemoteCollection(mockRemotes);
12+
}
13+
14+
public override RemoteCollection Remotes { get; }
15+
}
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace GitVersionCore.Tests.Mocks
2+
{
3+
using LibGit2Sharp;
4+
5+
public class MockRemote : Remote
6+
{
7+
public MockRemote(string name) => Name = name;
8+
9+
public override string Name { get; }
10+
}
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace GitVersionCore.Tests.Mocks
2+
{
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
6+
using LibGit2Sharp;
7+
8+
public class MockRemoteCollection : RemoteCollection, ICollection<Remote>
9+
{
10+
public List<Remote> Remotes;
11+
12+
public MockRemoteCollection(IEnumerable<MockRemote> mockRemotes)
13+
{
14+
Remotes = new List<Remote>(mockRemotes);
15+
}
16+
17+
public override IEnumerator<Remote> GetEnumerator() => Remotes.GetEnumerator();
18+
19+
IEnumerator<Remote> IEnumerable<Remote>.GetEnumerator() => GetEnumerator();
20+
21+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
22+
23+
public void Add(Remote item) => Remotes.Add(item);
24+
25+
public void Clear() => Remotes.Clear();
26+
27+
public bool Contains(Remote item) => Remotes.Contains(item);
28+
29+
public void CopyTo(Remote[] array, int arrayIndex) => Remotes.CopyTo(array, arrayIndex);
30+
31+
public bool Remove(Remote item) => Remotes.Remove(item);
32+
33+
public int Count => Remotes.Count;
34+
35+
public bool IsReadOnly => false;
36+
}
37+
}

src/GitVersionCore.Tests/Mocks/MockRepository.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
4+
using GitVersionCore.Tests.Mocks;
5+
36
using LibGit2Sharp;
47

58
public class MockRepository : IRepository
@@ -10,6 +13,7 @@ public MockRepository()
1013
{
1114
Tags = new MockTagCollection();
1215
Refs = new MockReferenceCollection();
16+
Network = new MockNetwork(new[] { new MockRemote("origin") });
1317
}
1418

1519
public void Dispose()

0 commit comments

Comments
 (0)