From 01b63a25ba475c1c7f4e9ca7577e6e625e2a2948 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 15 May 2025 21:21:44 +0200 Subject: [PATCH] Fix possible crash with auto-forwarding branches I'm not aware of any real scenario where this can happen, but we have seen one stack trace where it crashed with an out-of-bounds error in the range expression below, so there must be a way. And it seems better to guard against it anyway, rather than assuming it can't happen. --- pkg/gui/controllers/helpers/branches_helper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index 115c6070a..659f1dc3b 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -270,8 +270,12 @@ func (self *BranchesHelper) AutoForwardBranches() error { return nil } - allBranches := self.c.UserConfig().Git.AutoForwardBranches == "allBranches" branches := self.c.Model().Branches + if len(branches) == 0 { + return nil + } + + allBranches := self.c.UserConfig().Git.AutoForwardBranches == "allBranches" updateCommands := "" // The first branch is the currently checked out branch; skip it for _, branch := range branches[1:] {