Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,6 @@ public void CalculateVersionVariables_TwoBranchHasSameCommitHeadDetachedAndNotTa
environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, "true");

this.sp = GetServiceProvider(gitVersionOptions, environment: environment);

var _ = this.sp.GetRequiredService<Lazy<GitVersionContext>>()?.Value;

var sut = sp.GetRequiredService<IGitVersionCalculateTool>();

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

this.sp = GetServiceProvider(gitVersionOptions, environment: environment);

var _ = this.sp.GetRequiredService<Lazy<GitVersionContext>>()?.Value;

var sut = sp.GetRequiredService<IGitVersionCalculateTool>();

// Execute
Expand Down
7 changes: 5 additions & 2 deletions src/GitVersion.Core/Core/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public class GitPreparer : IGitPreparer
private readonly IRepositoryStore repositoryStore;
private readonly ICurrentBuildAgent buildAgent;
private readonly RetryAction<LockedFileException> retryAction;
private readonly Lazy<GitVersionContext> versionContext;
private GitVersionContext context => this.versionContext.Value;

private const string DefaultRemoteName = "origin";

public GitPreparer(ILog log, IEnvironment environment, ICurrentBuildAgent buildAgent, IOptions<GitVersionOptions> options,
IMutatingGitRepository repository, IGitRepositoryInfo repositoryInfo, IRepositoryStore repositoryStore)
IMutatingGitRepository repository, IGitRepositoryInfo repositoryInfo, IRepositoryStore repositoryStore, Lazy<GitVersionContext> versionContext)
{
this.log = log.NotNull();
this.environment = environment.NotNull();
Expand All @@ -32,6 +34,7 @@ public GitPreparer(ILog log, IEnvironment environment, ICurrentBuildAgent buildA
this.repositoryStore = repositoryStore.NotNull();
this.buildAgent = buildAgent.NotNull();
this.retryAction = new RetryAction<LockedFileException>();
this.versionContext = versionContext.NotNull();
}

public void Prepare()
Expand Down Expand Up @@ -241,7 +244,7 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool
this.log.Warning($"Choosing {branchWithoutSeparator.Name.Canonical} as it is the only branch without / or - in it. " + moveBranchMsg);
Checkout(branchWithoutSeparator.Name.Canonical);
}
else
else if (!this.context.IsCurrentCommitTagged)
{
throw new WarningException("Failed to try and guess branch to use. " + moveBranchMsg);
}
Expand Down
7 changes: 1 addition & 6 deletions src/GitVersion.Core/Core/GitVersionCalculateTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ public GitVersionCalculateTool(ILog log, INextVersionCalculator nextVersionCalcu

public VersionVariables CalculateVersionVariables()
{
bool isCurrentCommitTagged = this.versionContext.IsValueCreated && this.versionContext.Value.IsCurrentCommitTagged;

if (!isCurrentCommitTagged)
{
this.gitPreparer.Prepare(); //we need to prepare the repository before using it for version calculation
}
this.gitPreparer.Prepare(); //we need to prepare the repository before using it for version calculation

var gitVersionOptions = this.options.Value;

Expand Down