Skip to content

Git version calculating wrong version when building a tag #2413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 7, 2020
Merged
19 changes: 19 additions & 0 deletions src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal IEnumerable<BaseVersion> 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 =>
Expand All @@ -40,11 +40,12 @@ internal IEnumerable<BaseVersion> 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)
Expand Down