Skip to content

Commit 1293562

Browse files
committed
dont bump PreReleaseTag on specific commit
fixes #211
1 parent b2d676e commit 1293562

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
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/UncycloScenarios.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

Tests/Helpers/Lg2sHelperBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +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+
108109
protected static void AddTag(Repository repo, string tagName)
109110
{
110111
var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString());
111112
File.WriteAllText(randomFile, string.Empty);
112113
repo.Index.Stage(randomFile);
113114
var sign = Constants.SignatureNow();
114-
repo.ApplyTag(tagName, sign, "foo");
115+
repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo");
115116
}
116117
}

0 commit comments

Comments
 (0)