From f4c5bb33d96336901dbb92a7018a112be8c94fec Mon Sep 17 00:00:00 2001 From: Gerwin Jansen Date: Wed, 30 Sep 2020 08:53:16 +0200 Subject: [PATCH 1/4] Add failing test --- .../IntegrationTests/TagCheckoutScenarios.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs index 53f524871e..e3d7f6152e 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs @@ -28,5 +28,24 @@ public void GivenARepositoryWithSingleCommitAndSingleBranch() fixture.AssertFullSemver(taggedVersion); } + + [Test] + public void GivenARepositoryWithTwoTagsAndADevelopBranch() + { + using var fixture = new EmptyRepositoryFixture(); + const string firstVersion = "1.0"; + const string hotfixVersion = "1.0.1"; + + fixture.MakeACommit("init master"); + fixture.ApplyTag(firstVersion); + fixture.MakeACommit("hotfix"); + fixture.ApplyTag(hotfixVersion); + fixture.BranchTo("develop"); + fixture.MakeACommit("new feature"); + fixture.Checkout(hotfixVersion); + fixture.BranchTo("tags/1.0.1"); + + fixture.AssertFullSemver(hotfixVersion); + } } } From b5ba1f52d7ed1728d92a27cc576cb776cf96fb79 Mon Sep 17 00:00:00 2001 From: Gerwin Jansen Date: Sat, 3 Oct 2020 14:38:48 +0200 Subject: [PATCH 2/4] TaggedCommitVersionStrategy now prefers to return only the versions of tags on the current commit --- .../TaggedCommitVersionStrategy.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs index 5d3aa269ba..4b87a9418d 100644 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs +++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs @@ -30,7 +30,7 @@ internal IEnumerable GetTaggedVersions(Branch currentBranch, DateTi { var allTags = repositoryMetadataProvider.GetValidVersionTags(Context.Configuration.GitTagPrefix, olderThan); - var tagsOnBranch = currentBranch + var taggedVersions = currentBranch .Commits .SelectMany(commit => { return allTags.Where(t => IsValidTag(t.Item1, commit)); }) .Select(t => @@ -40,11 +40,12 @@ internal IEnumerable GetTaggedVersions(Branch currentBranch, DateTi return null; }) - .Where(a => a != null) - .Take(5) + .Where(versionTaggedCommit => versionTaggedCommit != null) + .Select(versionTaggedCommit => CreateBaseVersion(Context, versionTaggedCommit)) .ToList(); - return tagsOnBranch.Select(t => CreateBaseVersion(Context, t)); + var taggedVersionsOnCurrentCommit = taggedVersions.Where(version => !version.ShouldIncrement).ToList(); + return taggedVersionsOnCurrentCommit.Any() ? taggedVersionsOnCurrentCommit : taggedVersions; } private BaseVersion CreateBaseVersion(GitVersionContext context, VersionTaggedCommit version) From a8b5218234d6a42df951b96c2103f98ca76d9f1d Mon Sep 17 00:00:00 2001 From: Gerwin Jansen Date: Wed, 30 Sep 2020 08:53:16 +0200 Subject: [PATCH 3/4] Add failing test --- .../IntegrationTests/TagCheckoutScenarios.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs index 53f524871e..e3d7f6152e 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs @@ -28,5 +28,24 @@ public void GivenARepositoryWithSingleCommitAndSingleBranch() fixture.AssertFullSemver(taggedVersion); } + + [Test] + public void GivenARepositoryWithTwoTagsAndADevelopBranch() + { + using var fixture = new EmptyRepositoryFixture(); + const string firstVersion = "1.0"; + const string hotfixVersion = "1.0.1"; + + fixture.MakeACommit("init master"); + fixture.ApplyTag(firstVersion); + fixture.MakeACommit("hotfix"); + fixture.ApplyTag(hotfixVersion); + fixture.BranchTo("develop"); + fixture.MakeACommit("new feature"); + fixture.Checkout(hotfixVersion); + fixture.BranchTo("tags/1.0.1"); + + fixture.AssertFullSemver(hotfixVersion); + } } } From f7a5e5cce41572616cb0a57d5405402858548c2f Mon Sep 17 00:00:00 2001 From: Gerwin Jansen Date: Sat, 3 Oct 2020 14:38:48 +0200 Subject: [PATCH 4/4] TaggedCommitVersionStrategy now prefers to return only the versions of tags on the current commit --- .../TaggedCommitVersionStrategy.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs index 5d3aa269ba..4b87a9418d 100644 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs +++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs @@ -30,7 +30,7 @@ internal IEnumerable GetTaggedVersions(Branch currentBranch, DateTi { var allTags = repositoryMetadataProvider.GetValidVersionTags(Context.Configuration.GitTagPrefix, olderThan); - var tagsOnBranch = currentBranch + var taggedVersions = currentBranch .Commits .SelectMany(commit => { return allTags.Where(t => IsValidTag(t.Item1, commit)); }) .Select(t => @@ -40,11 +40,12 @@ internal IEnumerable GetTaggedVersions(Branch currentBranch, DateTi return null; }) - .Where(a => a != null) - .Take(5) + .Where(versionTaggedCommit => versionTaggedCommit != null) + .Select(versionTaggedCommit => CreateBaseVersion(Context, versionTaggedCommit)) .ToList(); - return tagsOnBranch.Select(t => CreateBaseVersion(Context, t)); + var taggedVersionsOnCurrentCommit = taggedVersions.Where(version => !version.ShouldIncrement).ToList(); + return taggedVersionsOnCurrentCommit.Any() ? taggedVersionsOnCurrentCommit : taggedVersions; } private BaseVersion CreateBaseVersion(GitVersionContext context, VersionTaggedCommit version)