Skip to content

Commit 58d7af2

Browse files
committed
Merge pull request #211 from Particular/exactTagOnRelease
should get exact version from tag
2 parents f36f6ea + 1293562 commit 58d7af2

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

AcceptanceTests/GitFlow/PatchScenarios.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public void PatchLatestReleaseExample()
2020
fixture.Repository.MakeACommit();
2121
fixture.AssertFullSemver("1.2.1-beta.1+1");
2222
fixture.Repository.ApplyTag("1.2.1-beta.1");
23-
fixture.AssertFullSemver("1.2.1-beta.2+1");
23+
fixture.AssertFullSemver("1.2.1-beta.1+1");
24+
fixture.Repository.MakeACommit();
25+
fixture.AssertFullSemver("1.2.1-beta.2+2");
2426

2527
// Merge hotfix branch to master
2628
fixture.Repository.Checkout("master");

AcceptanceTests/GitFlow/WikiScenarios.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ public void MinorReleaseExample()
7474
fixture.Repository.MakeACommit();
7575
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1");
7676

77-
// Apply beta.0 tag
77+
// Apply beta.0 tag should be exact tag
7878
fixture.Repository.ApplyTag("1.3.0-beta.1");
79-
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+1");
79+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1");
80+
81+
// Make a commit after a tag should bump up the beta
82+
fixture.Repository.MakeACommit();
83+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+2");
8084

8185
// Merge release branch to master
8286
fixture.Repository.Checkout("master");

GitVersionCore/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ protected SemanticVersion FindVersion(
4444

4545
if (tagVersion != null)
4646
{
47-
tagVersion.PreReleaseTag.Number++;
48-
semanticVersion.PreReleaseTag = tagVersion.PreReleaseTag;
47+
//If the tag is on the eact commit then dont bump the PreReleaseTag
48+
if (context.CurrentCommit.Sha != tagVersion.Commit.Sha)
49+
{
50+
tagVersion.SemVer.PreReleaseTag.Number++;
51+
}
52+
semanticVersion.PreReleaseTag = tagVersion.SemVer.PreReleaseTag;
4953
}
5054

5155
return semanticVersion;
@@ -71,7 +75,7 @@ bool IsMostRecentCommitTagged(GitVersionContext context, out SemanticVersion ver
7175
return false;
7276
}
7377

74-
SemanticVersion RetrieveMostRecentOptionalTagVersion(
78+
VersionTaggedCommit RetrieveMostRecentOptionalTagVersion(
7579
IRepository repository, SemanticVersion branchVersion, IEnumerable<Commit> take)
7680
{
7781
foreach (var commit in take)
@@ -91,7 +95,7 @@ SemanticVersion RetrieveMostRecentOptionalTagVersion(
9195
continue;
9296
}
9397

94-
return version;
98+
return new VersionTaggedCommit(commit, version);
9599
}
96100
}
97101

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"Major": 5,
3+
"Minor": 0,
4+
"Patch": 0,
5+
"PreReleaseTag": {
6+
"Name": "beta",
7+
"Number": 2
8+
},
9+
"BuildMetaData": {
10+
"CommitsSinceTag": 1,
11+
"Branch": "release-5.0.0",
12+
"ReleaseDate": {
13+
"OriginalDate": "<date replaced>",
14+
"OriginalCommitSha": "000000000000000000000000000000000000000",
15+
"Date": "<date replaced>",
16+
"CommitSha": "000000000000000000000000000000000000000"
17+
},
18+
"Sha": "000000000000000000000000000000000000000",
19+
"OtherMetaData": null
20+
}
21+
}

Tests/BranchFinders/ReleaseTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GitVersion;
22
using LibGit2Sharp;
33
using NUnit.Framework;
4+
using ObjectApproval;
45

56
[TestFixture]
67
public class ReleaseTests : Lg2sHelperBase
@@ -39,4 +40,22 @@ public void EnsureAReleaseBranchNameDoesNotExposeAStability()
3940
}
4041
}
4142

43+
[Test]
44+
public void Tag_on_commit_should_be_exact_tag()
45+
{
46+
var repoPath = Clone(ASBMTestRepoWorkingDirPath);
47+
using (var repo = new Repository(repoPath))
48+
{
49+
// Create a release branch from the parent of current develop tip
50+
repo.Branches.Add("release-5.0.0", "develop~").ForceCheckout();
51+
52+
AddOneCommitToHead(repo, "code");
53+
AddTag(repo, "5.0.0-beta2");
54+
55+
var finder = new ReleaseVersionFinder();
56+
57+
var version = finder.FindVersion(new GitVersionContext(repo, repo.Head));
58+
ObjectApprover.VerifyWithJson(version, Scrubbers.GuidAndDateScrubber);
59+
}
60+
}
4261
}

Tests/Helpers/Lg2sHelperBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,13 @@ protected static Commit AddOneCommitToHead(Repository repo, string type)
105105
var sign = Constants.SignatureNow();
106106
return repo.Commit(type + " commit", sign, sign);
107107
}
108+
109+
protected static void AddTag(Repository repo, string tagName)
110+
{
111+
var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString());
112+
File.WriteAllText(randomFile, string.Empty);
113+
repo.Index.Stage(randomFile);
114+
var sign = Constants.SignatureNow();
115+
repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo");
116+
}
108117
}

0 commit comments

Comments
 (0)