From b2011dca359fbf5a5dde7118fe2ad27a41410ed6 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 29 May 2024 16:25:41 +0200 Subject: [PATCH] Remove the cache invalidation logic from getMergeBase It is a valid case for a branch to share no history with any of the main branches, in which case git merge-base returns an error (and an empty string). Since we can't distinguish this from one of the main branches having been deleted, we shouldn't invalidate the cache in that case. --- pkg/commands/git_commands/commit_loader.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 737e4c077..86418453d 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -483,16 +483,17 @@ func (self *CommitLoader) getMergeBase(refName string) string { // We pass all configured main branches to the merge-base call; git will // return the base commit for the closest one. - output, err := self.cmd.New( + // We ignore errors from this call, since we can't distinguish whether the + // error is because one of the main branches has been deleted since the last + // call to determineMainBranches, or because the refName has no common + // history with any of the main branches. Since the former should happen + // very rarely, users must quit and restart lazygit to fix it; the latter is + // also not very common, but can totally happen and is not an error. + + output, _ := self.cmd.New( NewGitCmd("merge-base").Arg(refName).Arg(self.mainBranches...). ToArgv(), ).DontLog().RunWithOutput() - if err != nil { - // If there's an error, it must be because one of the main branches that - // used to exist when we called getExistingMainBranches() was deleted - // meanwhile. To fix this for next time, throw away our cache. - self.mainBranches = nil - } return ignoringWarnings(output) }