Skip to content

Commit 1fbfefa

Browse files
authored
Fix possible crash with auto-forwarding branches (#4565)
- **PR Description** Fix crash in AutoForwardBranches when the branches slice is empty. 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. (Hopefully) fixes #4564.
2 parents 43efdde + 01b63a2 commit 1fbfefa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/gui/controllers/helpers/branches_helper.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,12 @@ func (self *BranchesHelper) AutoForwardBranches() error {
270270
return nil
271271
}
272272

273-
allBranches := self.c.UserConfig().Git.AutoForwardBranches == "allBranches"
274273
branches := self.c.Model().Branches
274+
if len(branches) == 0 {
275+
return nil
276+
}
277+
278+
allBranches := self.c.UserConfig().Git.AutoForwardBranches == "allBranches"
275279
updateCommands := ""
276280
// The first branch is the currently checked out branch; skip it
277281
for _, branch := range branches[1:] {

0 commit comments

Comments
 (0)