@@ -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 buildA
3234 this . repositoryStore = repositoryStore . NotNull ( ) ;
3335 this . buildAgent = buildAgent . NotNull ( ) ;
3436 this . retryAction = new RetryAction < LockedFileException > ( ) ;
37+ this . versionContext = versionContext . NotNull ( ) ;
3538 }
3639
3740 public void Prepare ( )
@@ -241,7 +244,7 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool
241244 this . log . Warning ( $ "Choosing { branchWithoutSeparator . Name . Canonical } as it is the only branch without / or - in it. " + moveBranchMsg ) ;
242245 Checkout ( branchWithoutSeparator . Name . Canonical ) ;
243246 }
244- else
247+ else if ( ! this . context . IsCurrentCommitTagged )
245248 {
246249 throw new WarningException ( "Failed to try and guess branch to use. " + moveBranchMsg ) ;
247250 }
0 commit comments