Skip to content

Scoped prerelease number to prerelease label #756 #779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace GitVersionCore.Tests.VersionCalculation
{
using System;
using System.Collections.Generic;
using GitVersion;
using GitVersion.VersionCalculation;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;

Expand Down Expand Up @@ -94,5 +96,32 @@ public void PreReleaseTagCanUseBranchNameVariable()

version.ToString("f").ShouldBe("1.0.0-alpha.foo.1+2");
}

[Test]
public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery()
{
var config = new Config();
config.VersioningMode = VersioningMode.ContinuousDelivery;
config.Branches = new Dictionary<string, BranchConfig> {
{ "master", new BranchConfig() { Tag = "beta" } },
};

using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeACommit();

fixture.Repository.CreateBranch("feature/test");
fixture.Repository.Checkout("feature/test");
fixture.Repository.MakeATaggedCommit("0.1.0-test.1");
fixture.Repository.MakeACommit();

fixture.AssertFullSemver("0.1.0-test.2+2");

fixture.Repository.Checkout("master");
fixture.Repository.Merge(fixture.Repository.FindBranch("feature/test"), Constants.SignatureNow());

fixture.AssertFullSemver("0.1.0-beta.1+2");
}
}
}
}
5 changes: 2 additions & 3 deletions src/GitVersionCore/LibGitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Branch FindBranch(this IRepository repository, string branchName)
return repository.Branches.FirstOrDefault(x => x.Name == "origin/" + branchName);
}

public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IRepository repository, string tagPrefixRegex)
public static IEnumerable<SemanticVersion> GetVersionTagsOnBranch(this Branch branch, IRepository repository, string tagPrefixRegex)
{
var tags = repository.Tags.Select(t => t).ToList();

Expand All @@ -43,8 +43,7 @@ public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IReposi
if (SemanticVersion.TryParse(t.Name, tagPrefixRegex, out semver))
return new [] { semver };
return new SemanticVersion[0];
}))
.FirstOrDefault();
}));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersion.VersionCalculation
{
using System.Linq;
using System.Text.RegularExpressions;
using BaseVersionCalculators;

Expand Down Expand Up @@ -98,7 +99,10 @@ void UpdatePreReleaseTag(GitVersionContext context, SemanticVersion semanticVers
}
}

var lastTag = context.CurrentBranch.LastVersionTagOnBranch(context.Repository, context.Configuration.GitTagPrefix);
var lastTag = context.CurrentBranch
.GetVersionTagsOnBranch(context.Repository, context.Configuration.GitTagPrefix)
.FirstOrDefault(v => v.PreReleaseTag.Name == tagToUse);

if (number == null &&
lastTag != null &&
MajorMinorPatchEqual(lastTag, semanticVersion) &&
Expand Down