diff --git a/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs new file mode 100644 index 0000000000..53f524871e --- /dev/null +++ b/src/GitVersionCore.Tests/IntegrationTests/TagCheckoutScenarios.cs @@ -0,0 +1,32 @@ +using GitTools.Testing; +using NUnit.Framework; + +namespace GitVersionCore.Tests.IntegrationTests +{ + [TestFixture] + public class TagCheckoutScenarios + { + [Test] + public void GivenARepositoryWithSingleCommit() + { + using var fixture = new EmptyRepositoryFixture(); + const string taggedVersion = "1.0.3"; + fixture.Repository.MakeATaggedCommit(taggedVersion); + fixture.Checkout(taggedVersion); + + fixture.AssertFullSemver(taggedVersion); + } + + [Test] + public void GivenARepositoryWithSingleCommitAndSingleBranch() + { + using var fixture = new EmptyRepositoryFixture(); + const string taggedVersion = "1.0.3"; + fixture.Repository.MakeATaggedCommit(taggedVersion); + fixture.BranchTo("task1"); + fixture.Checkout(taggedVersion); + + fixture.AssertFullSemver(taggedVersion); + } + } +} diff --git a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs index 8a2a0361ca..15dbbbbb1c 100644 --- a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs @@ -35,7 +35,10 @@ public SemanticVersion FindVersion() log.Info($"Current commit is tagged with version {context.CurrentCommitTaggedVersion}, " + "version calculation is for metadata only."); } - EnsureHeadIsNotDetached(context); + else + { + EnsureHeadIsNotDetached(context); + } SemanticVersion taggedSemanticVersion = null;