Skip to content

Commit 12e23f7

Browse files
authored
Merge pull request #2951 from hyabean/fix-2927
invalid use of Lazy<GitVersionContext>, #2933 fix doesn't work actualy
2 parents 19462e1 + 93996d5 commit 12e23f7

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,6 @@ public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndNotTa
562562
environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true");
563563

564564
this.sp = GetServiceProvider(gitVersionOptions, environment: environment);
565-
566-
var _ = this.sp.GetRequiredService<Lazy<GitVersionContext>>()?.Value;
567-
568565
var sut = sp.GetRequiredService<IGitVersionCalculateTool>();
569566

570567
// Execute & Verify
@@ -594,9 +591,6 @@ public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndTagge
594591
environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true");
595592

596593
this.sp = GetServiceProvider(gitVersionOptions, environment: environment);
597-
598-
var _ = this.sp.GetRequiredService<Lazy<GitVersionContext>>()?.Value;
599-
600594
var sut = sp.GetRequiredService<IGitVersionCalculateTool>();
601595

602596
// Execute

src/GitVersion.Core/Core/GitPreparer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/GitVersion.Core/Core/GitVersionCalculateTool.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ public GitVersionCalculateTool(ILog log, INextVersionCalculator nextVersionCalcu
4040

4141
public VersionVariables CalculateVersionVariables()
4242
{
43-
bool isCurrentCommitTagged = this.versionContext.IsValueCreated && this.versionContext.Value.IsCurrentCommitTagged;
44-
45-
if (!isCurrentCommitTagged)
46-
{
47-
this.gitPreparer.Prepare(); //we need to prepare the repository before using it for version calculation
48-
}
43+
this.gitPreparer.Prepare(); //we need to prepare the repository before using it for version calculation
4944

5045
var gitVersionOptions = this.options.Value;
5146

0 commit comments

Comments
 (0)