diff --git a/AcceptanceTests/GitFlow/PatchScenarios.cs b/AcceptanceTests/GitFlow/PatchScenarios.cs index 054d6bdffc..0f85b8cde9 100644 --- a/AcceptanceTests/GitFlow/PatchScenarios.cs +++ b/AcceptanceTests/GitFlow/PatchScenarios.cs @@ -20,7 +20,9 @@ public void PatchLatestReleaseExample() fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.2.1-beta.1+1"); fixture.Repository.ApplyTag("1.2.1-beta.1"); - fixture.AssertFullSemver("1.2.1-beta.2+1"); + fixture.AssertFullSemver("1.2.1-beta.1+1"); + fixture.Repository.MakeACommit(); + fixture.AssertFullSemver("1.2.1-beta.2+2"); // Merge hotfix branch to master fixture.Repository.Checkout("master"); diff --git a/AcceptanceTests/GitFlow/WikiScenarios.cs b/AcceptanceTests/GitFlow/WikiScenarios.cs index 1abd279bce..7b2a41fde1 100644 --- a/AcceptanceTests/GitFlow/WikiScenarios.cs +++ b/AcceptanceTests/GitFlow/WikiScenarios.cs @@ -74,9 +74,13 @@ public void MinorReleaseExample() fixture.Repository.MakeACommit(); fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1"); - // Apply beta.0 tag + // Apply beta.0 tag should be exact tag fixture.Repository.ApplyTag("1.3.0-beta.1"); - fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+1"); + fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1"); + + // Make a commit after a tag should bump up the beta + fixture.Repository.MakeACommit(); + fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+2"); // Merge release branch to master fixture.Repository.Checkout("master"); diff --git a/GitVersionCore/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs b/GitVersionCore/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs index c47f94740d..5a0fa3daef 100644 --- a/GitVersionCore/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs +++ b/GitVersionCore/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs @@ -44,8 +44,12 @@ protected SemanticVersion FindVersion( if (tagVersion != null) { - tagVersion.PreReleaseTag.Number++; - semanticVersion.PreReleaseTag = tagVersion.PreReleaseTag; + //If the tag is on the eact commit then dont bump the PreReleaseTag + if (context.CurrentCommit.Sha != tagVersion.Commit.Sha) + { + tagVersion.SemVer.PreReleaseTag.Number++; + } + semanticVersion.PreReleaseTag = tagVersion.SemVer.PreReleaseTag; } return semanticVersion; @@ -71,7 +75,7 @@ bool IsMostRecentCommitTagged(GitVersionContext context, out SemanticVersion ver return false; } - SemanticVersion RetrieveMostRecentOptionalTagVersion( + VersionTaggedCommit RetrieveMostRecentOptionalTagVersion( IRepository repository, SemanticVersion branchVersion, IEnumerable take) { foreach (var commit in take) @@ -91,7 +95,7 @@ SemanticVersion RetrieveMostRecentOptionalTagVersion( continue; } - return version; + return new VersionTaggedCommit(commit, version); } } diff --git a/Tests/BranchFinders/ReleaseTests.Tag_on_commit_should_be_exact_tag.approved.txt b/Tests/BranchFinders/ReleaseTests.Tag_on_commit_should_be_exact_tag.approved.txt new file mode 100644 index 0000000000..94332dd962 --- /dev/null +++ b/Tests/BranchFinders/ReleaseTests.Tag_on_commit_should_be_exact_tag.approved.txt @@ -0,0 +1,21 @@ +{ + "Major": 5, + "Minor": 0, + "Patch": 0, + "PreReleaseTag": { + "Name": "beta", + "Number": 2 + }, + "BuildMetaData": { + "CommitsSinceTag": 1, + "Branch": "release-5.0.0", + "ReleaseDate": { + "OriginalDate": "", + "OriginalCommitSha": "000000000000000000000000000000000000000", + "Date": "", + "CommitSha": "000000000000000000000000000000000000000" + }, + "Sha": "000000000000000000000000000000000000000", + "OtherMetaData": null + } +} \ No newline at end of file diff --git a/Tests/BranchFinders/ReleaseTests.cs b/Tests/BranchFinders/ReleaseTests.cs index f5f3ae32c9..037c1eca14 100644 --- a/Tests/BranchFinders/ReleaseTests.cs +++ b/Tests/BranchFinders/ReleaseTests.cs @@ -1,6 +1,7 @@ using GitVersion; using LibGit2Sharp; using NUnit.Framework; +using ObjectApproval; [TestFixture] public class ReleaseTests : Lg2sHelperBase @@ -39,4 +40,22 @@ public void EnsureAReleaseBranchNameDoesNotExposeAStability() } } + [Test] + public void Tag_on_commit_should_be_exact_tag() + { + var repoPath = Clone(ASBMTestRepoWorkingDirPath); + using (var repo = new Repository(repoPath)) + { + // Create a release branch from the parent of current develop tip + repo.Branches.Add("release-5.0.0", "develop~").ForceCheckout(); + + AddOneCommitToHead(repo, "code"); + AddTag(repo, "5.0.0-beta2"); + + var finder = new ReleaseVersionFinder(); + + var version = finder.FindVersion(new GitVersionContext(repo, repo.Head)); + ObjectApprover.VerifyWithJson(version, Scrubbers.GuidAndDateScrubber); + } + } } \ No newline at end of file diff --git a/Tests/Helpers/Lg2sHelperBase.cs b/Tests/Helpers/Lg2sHelperBase.cs index d031da8c5e..82e3c884e7 100644 --- a/Tests/Helpers/Lg2sHelperBase.cs +++ b/Tests/Helpers/Lg2sHelperBase.cs @@ -105,4 +105,13 @@ protected static Commit AddOneCommitToHead(Repository repo, string type) var sign = Constants.SignatureNow(); return repo.Commit(type + " commit", sign, sign); } + + protected static void AddTag(Repository repo, string tagName) + { + var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString()); + File.WriteAllText(randomFile, string.Empty); + repo.Index.Stage(randomFile); + var sign = Constants.SignatureNow(); + repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo"); + } } \ No newline at end of file