From 15f0fb7be70b79ade922e77bcf2242c85e2dbf5a Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Thu, 28 Dec 2023 09:46:00 -0500 Subject: [PATCH] Fix `NonFastForwardException` in `Repository.CommittishIsParent` --- .../Components/Repository/Repository.cs | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index cd320cc892..2a362ff90c 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -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