lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Crashes when apply patch to previous commit

Open AngrySaltyFish24 opened this issue 7 months ago • 2 comments

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:

  1. Create an empty repo:
  • mkdir lists
  • cd lists
  • git init
  1. Creating a junk food shopping list and commit it
  • echo "pizza\nburger\nmilk\n" > junkfood
  • add and commit the file using the a and c keybindings on lazy git
  1. add a dairy shopping list
  • echo "cheese\n" > dairy
  • add and commit the file using the a and c keybindings on lazy git
  1. 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

AngrySaltyFish24 avatar Jun 04 '25 22:06 AngrySaltyFish24

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.

stefanhaller avatar Jun 05 '25 06:06 stefanhaller

Here's a fix: #4631

stefanhaller avatar Jun 09 '25 14:06 stefanhaller