Crashes when apply patch to previous commit
Describe the bug I found this bug following part of the wiki. https://github.com/jesseduffield/lazygit/wiki/Directly-Changing-Code-Stored-In-Commits#lazygit-solution
In essence, i want to move a code snippet from one commit to another. When trying to do this the application crashes with the following output
panic: runtime error: index out of range [2] with length 2
goroutine 740 [running]:
github.com/jesseduffield/lazygit/pkg/commands/git_commands.(*PatchCommands).MovePatchToSelectedCommit(0xc000242570, {0xc000894240, 0x2, 0xc000783de0?}, 0x1, 0x0)
github.com/jesseduffield/lazygit/pkg/commands/git_commands/patch.go:165 +0x674
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*CustomPatchOptionsMenuAction).handleMovePatchToSelectedCommit.func1({0x558a6b9f17c0?, 0xc000783e38?})
github.com/jesseduffield/lazygit/pkg/gui/controllers/custom_patch_options_menu_action.go:161 +0xf2
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*AppStatusHelper).WithWaitingStatusImpl.func1(0xc0008e3380?)
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/app_status_helper.go:69 +0x53
github.com/jesseduffield/lazygit/pkg/gui/status.(*StatusManager).WithWaitingStatus(0xc00030a0f0, {0x558a6b69eecc, 0x8}, 0xc0009456f0, 0xc000783ee0)
github.com/jesseduffield/lazygit/pkg/gui/status/status_manager.go:56 +0xd7
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*AppStatusHelper).WithWaitingStatusImpl(0xc000330a38, {0x558a6b69eecc, 0x8}, 0xc000945320, {0x558a6ba8dd60, 0xc000897700})
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/app_status_helper.go:68 +0xc7
github.com/jesseduffield/lazygit/pkg/gui.NewGui.func5.(*AppStatusHelper).WithWaitingStatus.1({0x558a6ba8dd60?, 0xc000897700?})
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/app_status_helper.go:63 +0x39
github.com/jesseduffield/gocui.(*Gui).onWorkerAux(0xc000334000, 0x558a6add1a72?, {0x558a6ba8dd60?, 0xc000897700?})
github.com/jesseduffield/[email protected]/gui.go:706 +0x65
github.com/jesseduffield/gocui.(*Gui).OnWorker.func1()
github.com/jesseduffield/[email protected]/gui.go:693 +0x2b
created by github.com/jesseduffield/gocui.(*Gui).OnWorker in goroutine 1
github.com/jesseduffield/[email protected]/gui.go:692 +0x90
To Reproduce Steps to reproduce the behavior:
- Create an empty repo:
mkdir listscd listsgit init
- Creating a junk food shopping list and commit it
echo "pizza\nburger\nmilk\n" > junkfood- add and commit the file using the
aandckeybindings on lazy git
- add a dairy shopping list
echo "cheese\n" > dairy- add and commit the file using the
aandckeybindings on lazy git
- attempt to move mik from the junkfood list to dairy using lazy git
- Navigate to commit panel
- select junk food and create a new patch (enter -> enter -> {use space to move milk})
- move to the commit where you added dairy
- press
and select "move patch to selected commit"
Expected behavior That the code snippet is moved.
In reproducible steps example this would mean moving milk to the dairies list
Version info: lazygit --version
commit=v0.51.1, build date=2025-05-23T11:46:20Z, build source=binaryRelease, version=0.51.1, os=linux, arch=amd64, git version=2.49.0
Run git --version and paste the result here
git version 2.49.0
Additional context installed through AUR on archlinux
also tested with master version
commit=ac7de7e8d, build date=20250604.221404, build source=unknown, version=v0.51.1.ac7de7e8d, os=linux, arch=amd64, git version=2.49.0
Thanks for the report. This only crashes when you try to move a patch from the very first commit of your repo to a later commit. I'll see if we can either support this case properly, or disable the command for this case if we can't.
Here's a fix: #4631