Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
take versions from branch names only when they are release (remove co…
…nfig flag and make it the default behavior); include remote release branches
  • Loading branch information
bert2 committed Dec 20, 2018
commit 9fd376c8110d7ab3e87b310bf781be9f4f0e3532
5 changes: 0 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
2015-10-23T12:23:15`) to setup an exclusion range. Effectively any commit before
`commits-before` will be ignored.

#### non-release-branches
By default all branches that have a semantic version in their name will be used
to calculate the version. This can be restricted to [release branches](#is-release-branch)
by setting this flag to `true`. Default is `false`.

## Branch configuration
Then we have branch specific configuration, which looks something like this:

Expand Down
7 changes: 2 additions & 5 deletions src/GitVersionCore.Tests/Configuration/IgnoreConfigTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using GitVersion;
using NUnit.Framework;
Expand All @@ -17,7 +17,6 @@ public void CanDeserialize()
ignore:
sha: [b6c0c9fda88830ebcd563e500a5a7da5a1658e98]
commits-before: 2015-10-23T12:23:15
non-release-branches: true
";

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

Expand Down Expand Up @@ -66,7 +64,6 @@ public void WhenNotInConfigShouldHaveDefaults()
config.Ignore.ShouldNotBeNull();
config.Ignore.SHAs.ShouldBeEmpty();
config.Ignore.Before.ShouldBeNull();
config.Ignore.NonReleaseBranches.ShouldBeNull();
}
}

Expand All @@ -84,4 +81,4 @@ public void WhenBadDateFormatShouldFail()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GitTools.Testing;
using GitTools.Testing;
using GitVersionCore.Tests;
using LibGit2Sharp;
using NUnit.Framework;
Expand All @@ -15,10 +15,10 @@ public void CanTakeVersionFromReleaseBranch()
const string TaggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("alpha-2.0.0");
Commands.Checkout(fixture.Repository, "alpha-2.0.0");
fixture.Repository.CreateBranch("release/beta-2.0.0");
Commands.Checkout(fixture.Repository, "release/beta-2.0.0");

fixture.AssertFullSemver("2.0.0-alpha.1+0");
fixture.AssertFullSemver("2.0.0-beta.1+0");
}
}

Expand Down Expand Up @@ -57,4 +57,4 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
version.SemVer.ShouldBe("1.0.0-alpha.1");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
namespace GitVersionCore.Tests.IntegrationTests
{
using System.Collections.Generic;
using System.Linq;

using GitTools.Testing;

using GitVersion;

using GitVersionCore.Tests;

using LibGit2Sharp;

using NUnit.Framework;

[TestFixture]
public class VersionInCurrentBranchNameScenarios : TestBase
{
[Test]
public void TakesVersionFromNameOfAnyBranchByDefault()
public void TakesVersionFromNameOfReleaseBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.BranchTo("feature/upgrade-power-level-to-9000.0.1");
fixture.BranchTo("release/2.0.0");

fixture.AssertFullSemver("9000.0.1-upgrade-power-level-to.1+0");
fixture.AssertFullSemver("2.0.0-beta.1+0");
}
}

[Test]
public void TakesVersionOnlyFromNameOfReleaseBranchByConfig()
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
{
var config = new Config { Ignore = new IgnoreConfig { NonReleaseBranches = true } };

using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.BranchTo("feature/upgrade-power-level-to-9000.0.1");

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

Expand All @@ -41,7 +43,6 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
{
var config = new Config
{
Ignore = new IgnoreConfig { NonReleaseBranches = true },
Branches = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }
};

Expand All @@ -52,5 +53,20 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
fixture.AssertFullSemver(config, "2.0.0+1");
}
}

[Test]
public void TakesVersionFromNameOfRemoteReleaseBranch()
{
using (var fixture = new RemoteRepositoryFixture())
{
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);

fixture.LocalRepositoryFixture.Checkout("origin/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0-beta.1+1");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
namespace GitVersionCore.Tests.IntegrationTests
{
using System.Collections.Generic;
using System.Linq;

using GitTools.Testing;

using GitVersion;

using GitVersionCore.Tests;

using LibGit2Sharp;

using NUnit.Framework;

[TestFixture]
public class VersionsInMergedBranchNamesScenarios : TestBase
public class VersionInMergedBranchNameScenarios : TestBase
{
[Test]
public void TakesVersionFromNameOfAnyBranchByDefault()
public void TakesVersionFromNameOfReleaseBranch()
{
using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.CreateAndMergeBranchIntoDevelop("feature/upgrade-power-level-to-9000.0.1");
fixture.CreateAndMergeBranchIntoDevelop("release/2.0.0");

fixture.AssertFullSemver("9000.1.0-alpha.0");
fixture.AssertFullSemver("2.1.0-alpha.2");
}
}

[Test]
public void TakesVersionOnlyFromNameOfReleaseBranchByConfig()
public void DoesNotTakeVersionFromNameOfNonReleaseBranch()
{
var config = new Config { Ignore = new IgnoreConfig { NonReleaseBranches = true } };

using (var fixture = new BaseGitFlowRepositoryFixture("1.0.0"))
{
fixture.CreateAndMergeBranchIntoDevelop("pull-request/improved-by-upgrading-some-lib-to-4.5.6");
fixture.CreateAndMergeBranchIntoDevelop("release/2.0.0");
fixture.CreateAndMergeBranchIntoDevelop("hotfix/downgrade-some-lib-to-3.2.1-to-avoid-breaking-changes");

fixture.AssertFullSemver(config, "2.1.0-alpha.4");
fixture.AssertFullSemver("1.1.0-alpha.5");
}
}

Expand All @@ -44,7 +44,6 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
{
var config = new Config
{
Ignore = new IgnoreConfig { NonReleaseBranches = true },
Branches = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } }
};

Expand All @@ -55,6 +54,21 @@ public void TakesVersionFromNameOfBranchThatIsReleaseByConfig()
fixture.AssertFullSemver(config, "2.1.0-alpha.2");
}
}

[Test]
public void TakesVersionFromNameOfRemoteReleaseBranch()
{
using (var fixture = new RemoteRepositoryFixture())
{
fixture.BranchTo("release/2.0.0");
fixture.MakeACommit();
Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null);

fixture.LocalRepositoryFixture.MergeNoFF("origin/release/2.0.0");

fixture.LocalRepositoryFixture.AssertFullSemver("2.0.0+0");
}
}
}

internal static class BaseGitFlowRepositoryFixtureExtensions
Expand Down
16 changes: 16 additions & 0 deletions src/GitVersionCore.Tests/Mocks/MockNetwork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace GitVersionCore.Tests.Mocks
{
using System.Collections.Generic;

using LibGit2Sharp;

public class MockNetwork : Network
{
public MockNetwork(IEnumerable<MockRemote> mockRemotes)
{
Remotes = new MockRemoteCollection(mockRemotes);
}

public override RemoteCollection Remotes { get; }
}
}
11 changes: 11 additions & 0 deletions src/GitVersionCore.Tests/Mocks/MockRemote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GitVersionCore.Tests.Mocks
{
using LibGit2Sharp;

public class MockRemote : Remote
{
public MockRemote(string name) => Name = name;

public override string Name { get; }
}
}
37 changes: 37 additions & 0 deletions src/GitVersionCore.Tests/Mocks/MockRemoteCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace GitVersionCore.Tests.Mocks
{
using System.Collections;
using System.Collections.Generic;

using LibGit2Sharp;

public class MockRemoteCollection : RemoteCollection, ICollection<Remote>
{
public List<Remote> Remotes;

public MockRemoteCollection(IEnumerable<MockRemote> mockRemotes)
{
Remotes = new List<Remote>(mockRemotes);
}

public override IEnumerator<Remote> GetEnumerator() => Remotes.GetEnumerator();

IEnumerator<Remote> IEnumerable<Remote>.GetEnumerator() => GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public void Add(Remote item) => Remotes.Add(item);

public void Clear() => Remotes.Clear();

public bool Contains(Remote item) => Remotes.Contains(item);

public void CopyTo(Remote[] array, int arrayIndex) => Remotes.CopyTo(array, arrayIndex);

public bool Remove(Remote item) => Remotes.Remove(item);

public int Count => Remotes.Count;

public bool IsReadOnly => false;
}
}
4 changes: 4 additions & 0 deletions src/GitVersionCore.Tests/Mocks/MockRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;

using GitVersionCore.Tests.Mocks;

using LibGit2Sharp;

public class MockRepository : IRepository
Expand All @@ -10,6 +13,7 @@ public MockRepository()
{
Tags = new MockTagCollection();
Refs = new MockReferenceCollection();
Network = new MockNetwork(new[] { new MockRemote("origin") });
}

public void Dispose()
Expand Down
Loading