@@ -18,11 +18,13 @@ public class GitPreparer : IGitPreparer
1818 private readonly IRepositoryStore repositoryStore ;
1919 private readonly ICurrentBuildAgent ? buildAgent ;
2020 private readonly RetryAction < LockedFileException > retryAction ;
21+ private readonly Lazy < GitVersionContext > versionContext ;
22+ private GitVersionContext context => this . versionContext . Value ;
2123
2224 private const string DefaultRemoteName = "origin" ;
2325
2426 public GitPreparer ( ILog log , IEnvironment environment , ICurrentBuildAgent ? buildAgent , IOptions < GitVersionOptions > options ,
25- IMutatingGitRepository repository , IGitRepositoryInfo repositoryInfo , IRepositoryStore repositoryStore )
27+ IMutatingGitRepository repository , IGitRepositoryInfo repositoryInfo , IRepositoryStore repositoryStore , Lazy < GitVersionContext > versionContext )
2628 {
2729 this . log = log . NotNull ( ) ;
2830 this . environment = environment . NotNull ( ) ;
@@ -32,6 +34,7 @@ public GitPreparer(ILog log, IEnvironment environment, ICurrentBuildAgent? build
3234 this . repositoryStore = repositoryStore . NotNull ( ) ;
3335 this . buildAgent = buildAgent ;
3436 this . retryAction = new RetryAction < LockedFileException > ( ) ;
37+ this . versionContext = versionContext . NotNull ( ) ;
3538 }
3639
3740 public void Prepare ( )
@@ -245,7 +248,7 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool
245248 this . log . Warning ( $ "Choosing { branchWithoutSeparator . Name . Canonical } as it is the only branch without / or - in it. " + moveBranchMsg ) ;
246249 Checkout ( branchWithoutSeparator . Name . Canonical ) ;
247250 }
248- else
251+ else if ( ! this . context . IsCurrentCommitTagged )
249252 {
250253 throw new WarningException ( "Failed to try and guess branch to use. " + moveBranchMsg ) ;
251254 }
0 commit comments