Skip to content

Commit

Permalink
Added tag-prefix configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeGinnivan committed Nov 16, 2014
1 parent bb39373 commit 31d4208
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
26 changes: 26 additions & 0 deletions GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,30 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionS
fixture.AssertFullSemver("1.1.0+0");
}
}

[Test]
public void CanSpecifyTagPrefixes()
{
using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "version-"}))
{
const string TaggedVersion = "version-1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);

fixture.AssertFullSemver("1.0.4+5");
}
}

[Test]
public void CanSpecifyTagPrefixesAsRegex()
{
using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "[version-|v]"}))
{
const string TaggedVersion = "v1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);

fixture.AssertFullSemver("1.0.4+5");
}
}
}
4 changes: 4 additions & 0 deletions GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public Config()
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
DevelopBranchTag = "unstable";
ReleaseBranchTag = "beta";
TagPrefix = "v";
}

public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; }
Expand All @@ -18,5 +19,8 @@ public Config()

[YamlAlias("release-branch-tag")]
public string ReleaseBranchTag { get; set; }

[YamlAlias("tag-prefix")]
public string TagPrefix { get; set; }
}
}
4 changes: 3 additions & 1 deletion GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersion
{
using System.Linq;
using System.Text.RegularExpressions;
using LibGit2Sharp;

public class LastTaggedReleaseFinder
Expand All @@ -16,8 +17,9 @@ public bool GetVersion(out VersionTaggedCommit versionTaggedCommit)
{
var tags = context.Repository.Tags.Select(t =>
{
var match = Regex.Match(t.Name, string.Format("({0})?(?<version>.*)", context.Configuration.TagPrefix));
SemanticVersion version;
if (SemanticVersion.TryParse(t.Name.TrimStart('v'), out version))
if (SemanticVersion.TryParse(match.Groups["version"].Value, out version))
{
return new VersionTaggedCommit((Commit)t.Target, version);
}
Expand Down

0 comments on commit 31d4208

Please sign in to comment.