Skip to content

crash when drag selecting and then staging ranges #4479

@ambyjkl

Description

@ambyjkl

Sometimes when drag selecting a range using mouse, and then staging it, there is a crash

To Reproduce
Steps to reproduce the behavior:

  1. Drag select a range
  2. Spacebar to stage

Expected behavior
It always works, does not panic

Version info:

commit=v0.48.0, build date=2025-03-01T07:57:57Z, build source=binaryRelease, version=0.48.0, os=linux, arch=amd64, git version=2.49.0

Additional context
stack trace:

panic: runtime error: index out of range [65] with length 64

goroutine 1 [running]:
github.com/jesseduffield/lazygit/pkg/gui/patch_exploring.(*State).SelectedPatchRange(0xc000218620)
        github.com/jesseduffield/lazygit/pkg/gui/patch_exploring/state.go:284 +0x48
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*StagingController).applySelection(0xc000279740, 0x0)
        github.com/jesseduffield/lazygit/pkg/gui/controllers/staging_controller.go:237 +0x125
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*StagingController).applySelectionAndRefresh(0xc000279740, 0x30?)
        github.com/jesseduffield/lazygit/pkg/gui/controllers/staging_controller.go:220 +0x1c
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*StagingController).ToggleStaged(0x1?)
        github.com/jesseduffield/lazygit/pkg/gui/controllers/staging_controller.go:195 +0xa5
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).callKeybindingHandler(0xc000294008, 0xc000002380?)
        github.com/jesseduffield/lazygit/pkg/gui/keybindings.go:468 +0x10a
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).SetKeybinding.func1()
        github.com/jesseduffield/lazygit/pkg/gui/keybindings.go:413 +0x1b
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).SetKeybinding.(*Gui).wrappedHandler.func3(0x0?, 0xc0043c1520?)
        github.com/jesseduffield/lazygit/pkg/gui/keybindings.go:407 +0x13
github.com/jesseduffield/gocui.(*Gui).execKeybinding(0xc0043c1460?, 0x5970b067d414?, 0xc0043c156c?)
        github.com/jesseduffield/gocui@v0.3.1-0.20250220081214-b376cb0857ac/gui.go:1553 +0x4a
github.com/jesseduffield/gocui.(*Gui).execKeybindings(0xc000200a80, 0xc0002d18c8, 0xc0043c1580)
        github.com/jesseduffield/gocui@v0.3.1-0.20250220081214-b376cb0857ac/gui.go:1521 +0x418
github.com/jesseduffield/gocui.(*Gui).onKey(0xc000278088?, 0xc0043c1508?)
        github.com/jesseduffield/gocui@v0.3.1-0.20250220081214-b376cb0857ac/gui.go:1328 +0x4d
github.com/jesseduffield/gocui.(*Gui).handleEvent(0xc000278060?, 0xc0043c1568?)
        github.com/jesseduffield/gocui@v0.3.1-0.20250220081214-b376cb0857ac/gui.go:845 +0x2f
github.com/jesseduffield/gocui.(*Gui).processEvent(0xc000200a80)
        github.com/jesseduffield/gocui@v0.3.1-0.20250220081214-b376cb0857ac/gui.go:799 +0x226
github.com/jesseduffield/gocui.(*Gui).MainLoop(0xc000200a80)
        github.com/jesseduffield/gocui@v0.3.1-0.20250220081214-b376cb0857ac/gui.go:778 +0xea
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).Run(0xc000294008, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
        github.com/jesseduffield/lazygit/pkg/gui/gui.go:855 +0x525
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError.func1()
        github.com/jesseduffield/lazygit/pkg/gui/gui.go:861 +0x48
github.com/jesseduffield/lazygit/pkg/utils.SafeWithError(0xc00004d918?)
        github.com/jesseduffield/lazygit/pkg/utils/utils.go:99 +0x56
github.com/jesseduffield/lazygit/pkg/gui.(*Gui).RunAndHandleError(0xc000294008, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}})
        github.com/jesseduffield/lazygit/pkg/gui/gui.go:860 +0xff
github.com/jesseduffield/lazygit/pkg/app.(*App).Run(...)
        github.com/jesseduffield/lazygit/pkg/app/app.go:270
github.com/jesseduffield/lazygit/pkg/app.Run({0x5970b12927f8?, 0xc00019c370?}, 0xc000244700, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}})
        github.com/jesseduffield/lazygit/pkg/app/app.go:48 +0xda
github.com/jesseduffield/lazygit/pkg/app.Start(0xc00004df00, {0x0, 0x0})
        github.com/jesseduffield/lazygit/pkg/app/entry_point.go:168 +0xd45
main.main()
        github.com/jesseduffield/lazygit/main.go:23 +0x98

I have not tried the latest master commit

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions