@@ -18,11 +18,13 @@ public class GitPreparer : IGitPreparer
18
18
private readonly IRepositoryStore repositoryStore ;
19
19
private readonly ICurrentBuildAgent buildAgent ;
20
20
private readonly RetryAction < LockedFileException > retryAction ;
21
+ private readonly Lazy < GitVersionContext > versionContext ;
22
+ private GitVersionContext context => this . versionContext . Value ;
21
23
22
24
private const string DefaultRemoteName = "origin" ;
23
25
24
26
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 )
26
28
{
27
29
this . log = log . NotNull ( ) ;
28
30
this . environment = environment . NotNull ( ) ;
@@ -32,6 +34,7 @@ public GitPreparer(ILog log, IEnvironment environment, ICurrentBuildAgent buildA
32
34
this . repositoryStore = repositoryStore . NotNull ( ) ;
33
35
this . buildAgent = buildAgent . NotNull ( ) ;
34
36
this . retryAction = new RetryAction < LockedFileException > ( ) ;
37
+ this . versionContext = versionContext . NotNull ( ) ;
35
38
}
36
39
37
40
public void Prepare ( )
@@ -241,7 +244,7 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool
241
244
this . log . Warning ( $ "Choosing { branchWithoutSeparator . Name . Canonical } as it is the only branch without / or - in it. " + moveBranchMsg ) ;
242
245
Checkout ( branchWithoutSeparator . Name . Canonical ) ;
243
246
}
244
- else
247
+ else if ( ! this . context . IsCurrentCommitTagged )
245
248
{
246
249
throw new WarningException ( "Failed to try and guess branch to use. " + moveBranchMsg ) ;
247
250
}
0 commit comments