Skip to content

Commit dacb3ad

Browse files
author
jianghongyuan
committed
error use of Lazy<GitVersionContext>, #2933 fix doesn't work actualy
1 parent 9fc71b3 commit dacb3ad

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
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.GetService<Lazy<GitVersionContext>>()?.Value;
567-
568565
var sut = sp.GetService<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.GetService<Lazy<GitVersionContext>>()?.Value;
599-
600594
var sut = sp.GetService<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? 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
}

src/GitVersion.Core/Core/GitVersionCalculateTool.cs

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

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

5145
var gitVersionOptions = this.options.Value;
5246

0 commit comments

Comments
 (0)