1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-27 23:08:02 +02:00

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.
This commit is contained in:
Stefan Haller 2025-05-21 08:24:58 +02:00 committed by GitHub
commit 1fbfefa625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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:] {