From a82134f41c60622166ad56c2b2c7f83e1989be77 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 16 May 2023 20:45:43 +1000 Subject: [PATCH] Fix race condition Our refresh code may try to push a context. It does this in two places: 1) when all merge conflicts are resolved, we push a 'continue merge?' confirmation context 2) when all conflicts of a given file are resolved and we're in the merge conflicts context, we push the files context. Sometimes we push the confirmation context and then push the files context over it, so the user never sees the confirmation context. This commit fixes the race condition by adding a check to ensure that we're still in the merge conflicts panel before we try escaping from it --- pkg/gui/controllers/helpers/merge_conflicts_helper.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/helpers/merge_conflicts_helper.go b/pkg/gui/controllers/helpers/merge_conflicts_helper.go index 3610e28c8..e6a56bfae 100644 --- a/pkg/gui/controllers/helpers/merge_conflicts_helper.go +++ b/pkg/gui/controllers/helpers/merge_conflicts_helper.go @@ -56,7 +56,15 @@ func (self *MergeConflictsHelper) EscapeMerge() error { // doing this in separate UI thread so that we're not still holding the lock by the time refresh the file self.c.OnUIThread(func() error { - return self.c.PushContext(self.c.Contexts().Files) + // There is a race condition here: refreshing the files scope can trigger the + // confirmation context to be pushed if all conflicts are resolved (prompting + // to continue the merge/rebase. In that case, we don't want to then push the + // files context over it. + // So long as both places call OnUIThread, we're fine. + if self.c.IsCurrentContext(self.c.Contexts().MergeConflicts) { + return self.c.PushContext(self.c.Contexts().Files) + } + return nil }) return nil }