diff --git a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs index 5600abb0ca..35540a74f7 100644 --- a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs +++ b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs @@ -562,9 +562,6 @@ public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndNotTa environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true"); this.sp = GetServiceProvider(gitVersionOptions, environment: environment); - - var _ = this.sp.GetRequiredService>()?.Value; - var sut = sp.GetRequiredService(); // Execute & Verify @@ -594,9 +591,6 @@ public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndTagge environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true"); this.sp = GetServiceProvider(gitVersionOptions, environment: environment); - - var _ = this.sp.GetRequiredService>()?.Value; - var sut = sp.GetRequiredService(); // Execute diff --git a/src/GitVersion.Core/Core/GitPreparer.cs b/src/GitVersion.Core/Core/GitPreparer.cs index f01922af08..4f5bc4f86c 100644 --- a/src/GitVersion.Core/Core/GitPreparer.cs +++ b/src/GitVersion.Core/Core/GitPreparer.cs @@ -18,11 +18,13 @@ public class GitPreparer : IGitPreparer private readonly IRepositoryStore repositoryStore; private readonly ICurrentBuildAgent buildAgent; private readonly RetryAction retryAction; + private readonly Lazy versionContext; + private GitVersionContext context => this.versionContext.Value; private const string DefaultRemoteName = "origin"; public GitPreparer(ILog log, IEnvironment environment, ICurrentBuildAgent buildAgent, IOptions options, - IMutatingGitRepository repository, IGitRepositoryInfo repositoryInfo, IRepositoryStore repositoryStore) + IMutatingGitRepository repository, IGitRepositoryInfo repositoryInfo, IRepositoryStore repositoryStore, Lazy versionContext) { this.log = log.NotNull(); this.environment = environment.NotNull(); @@ -32,6 +34,7 @@ public GitPreparer(ILog log, IEnvironment environment, ICurrentBuildAgent buildA this.repositoryStore = repositoryStore.NotNull(); this.buildAgent = buildAgent.NotNull(); this.retryAction = new RetryAction(); + this.versionContext = versionContext.NotNull(); } public void Prepare() @@ -241,7 +244,7 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool this.log.Warning($"Choosing {branchWithoutSeparator.Name.Canonical} as it is the only branch without / or - in it. " + moveBranchMsg); Checkout(branchWithoutSeparator.Name.Canonical); } - else + else if (!this.context.IsCurrentCommitTagged) { throw new WarningException("Failed to try and guess branch to use. " + moveBranchMsg); } diff --git a/src/GitVersion.Core/Core/GitVersionCalculateTool.cs b/src/GitVersion.Core/Core/GitVersionCalculateTool.cs index 5c975d09d7..6dcb80c083 100644 --- a/src/GitVersion.Core/Core/GitVersionCalculateTool.cs +++ b/src/GitVersion.Core/Core/GitVersionCalculateTool.cs @@ -40,12 +40,7 @@ public GitVersionCalculateTool(ILog log, INextVersionCalculator nextVersionCalcu public VersionVariables CalculateVersionVariables() { - bool isCurrentCommitTagged = this.versionContext.IsValueCreated && this.versionContext.Value.IsCurrentCommitTagged; - - if (!isCurrentCommitTagged) - { - this.gitPreparer.Prepare(); //we need to prepare the repository before using it for version calculation - } + this.gitPreparer.Prepare(); //we need to prepare the repository before using it for version calculation var gitVersionOptions = this.options.Value;