Fix NonFastForwardException in Repository.CommittishIsParent

This commit is contained in:
Jordan Dominion
2023-12-28 09:46:00 -05:00
parent c9024ebcf1
commit 15f0fb7be7
@@ -800,21 +800,32 @@ namespace Tgstation.Server.Host.Components.Repository
cancellationToken.ThrowIfCancellationRequested();
var startSha = Head;
var mergeResult = libGitRepo.Merge(
targetCommit,
new Signature(
DefaultCommitterName,
DefaultCommitterEmail,
DateTimeOffset.UtcNow),
new MergeOptions
{
FastForwardStrategy = FastForwardStrategy.FastForwardOnly,
FailOnConflict = true,
});
logger.LogTrace("Testing if {committish} is a parent of {startSha}...", committish, startSha);
MergeResult mergeResult;
try
{
mergeResult = libGitRepo.Merge(
targetCommit,
new Signature(
DefaultCommitterName,
DefaultCommitterEmail,
DateTimeOffset.UtcNow),
new MergeOptions
{
FastForwardStrategy = FastForwardStrategy.FastForwardOnly,
FailOnConflict = true,
});
}
catch (NonFastForwardException ex)
{
logger.LogTrace(ex, "{committish} is not a parent of {startSha}", committish, startSha);
return false;
}
if (mergeResult.Status == MergeStatus.UpToDate)
return true;
logger.LogTrace("{committish} is not a parent of {startSha} ({mergeStatus}). Moving back...", committish, startSha, mergeResult.Status);
commands.Checkout(
libGitRepo,
new CheckoutOptions