Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
- adds trouble shooting information for GitTools#1627
Browse files Browse the repository at this point in the history
  • Loading branch information
rominator1983 committed Oct 25, 2022
1 parent 808f8ba commit a700214
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/GitVersion.Core/Core/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,45 +156,47 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool
var expectedSha = this.repository.Head.Tip?.Sha;
var expectedBranchName = this.repository.Head.Name.Canonical;

try
var remote = EnsureOnlyOneRemoteIsDefined();
EnsureRepositoryHeadDuringNormalisation(nameof(EnsureOnlyOneRemoteIsDefined), expectedSha);
FetchRemotesIfRequired(remote, noFetch, authentication);
EnsureRepositoryHeadDuringNormalisation(nameof(FetchRemotesIfRequired), expectedSha);
EnsureLocalBranchExistsForCurrentBranch(remote, currentBranchName);
EnsureRepositoryHeadDuringNormalisation(nameof(EnsureLocalBranchExistsForCurrentBranch), expectedSha);
CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(remote.Name);
EnsureRepositoryHeadDuringNormalisation(nameof(CreateOrUpdateLocalBranchesFromRemoteTrackingOnes), expectedSha);

var currentBranch = this.repository.Branches.FirstOrDefault(x => x.Name.EquivalentTo(currentBranchName));
// Bug fix for https://github.com/GitTools/GitVersion/issues/1754, head maybe have been changed
// if this is a dynamic repository. But only allow this in case the branches are different (branch switch)
if (expectedSha != this.repository.Head.Tip?.Sha)
{
var remote = EnsureOnlyOneRemoteIsDefined();

FetchRemotesIfRequired(remote, noFetch, authentication);
EnsureLocalBranchExistsForCurrentBranch(remote, currentBranchName);
CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(remote.Name);

var currentBranch = this.repository.Branches.FirstOrDefault(x => x.Name.EquivalentTo(currentBranchName));
// Bug fix for https://github.com/GitTools/GitVersion/issues/1754, head maybe have been changed
// if this is a dynamic repository. But only allow this in case the branches are different (branch switch)
if (expectedSha != this.repository.Head.Tip?.Sha)
if (isDynamicRepository || currentBranch is null || !this.repository.Head.Equals(currentBranch))
{
if (isDynamicRepository || currentBranch is null || !this.repository.Head.Equals(currentBranch))
{
var newExpectedSha = this.repository.Head.Tip?.Sha;
var newExpectedBranchName = this.repository.Head.Name.Canonical;
var newExpectedSha = this.repository.Head.Tip?.Sha;
var newExpectedBranchName = this.repository.Head.Name.Canonical;

this.log.Info($"Head has moved from '{expectedBranchName} | {expectedSha}' => '{newExpectedBranchName} | {newExpectedSha}', allowed since this is a dynamic repository");
this.log.Info($"Head has moved from '{expectedBranchName} | {expectedSha}' => '{newExpectedBranchName} | {newExpectedSha}', allowed since this is a dynamic repository");

expectedSha = newExpectedSha;
}
expectedSha = newExpectedSha;
}

EnsureHeadIsAttachedToBranch(currentBranchName, authentication);
}
finally

EnsureHeadIsAttachedToBranch(currentBranchName, authentication);
EnsureRepositoryHeadDuringNormalisation(nameof(EnsureHeadIsAttachedToBranch), expectedSha);
}

private void EnsureRepositoryHeadDuringNormalisation(string occasion, string expectedSha)
{
if (this.repository.Head.Tip?.Sha != expectedSha)
{
if (this.repository.Head.Tip?.Sha != expectedSha)
if (this.environment.GetEnvironmentVariable("IGNORE_NORMALISATION_GIT_HEAD_MOVE") != "1")
{
if (this.environment.GetEnvironmentVariable("IGNORE_NORMALISATION_GIT_HEAD_MOVE") != "1")
{
// Whoa, HEAD has moved, it shouldn't have. We need to blow up because there is a bug in normalisation
throw new BugException($@"GitVersion has a bug, your HEAD has moved after repo normalisation.
// Whoa, HEAD has moved, it shouldn't have. We need to blow up because there is a bug in normalisation
throw new BugException($@"GitVersion has a bug, your HEAD has moved after repo normalisation after step '{occasion}'
To disable this error set an environmental variable called IGNORE_NORMALISATION_GIT_HEAD_MOVE to 1
Please run `git {GitExtensions.CreateGitLogArgs(100)}` and submit it along with your build log (with personal info removed) in a new issue at https://github.com/GitTools/GitVersion");
}
}
}
}
Expand Down

0 comments on commit a700214

Please sign in to comment.