Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash moving patch into new commit (index out of range) #2828

Closed
alexpopov opened this issue Jul 25, 2023 · 3 comments · Fixed by #2829
Closed

Crash moving patch into new commit (index out of range) #2828

alexpopov opened this issue Jul 25, 2023 · 3 comments · Fixed by #2829
Labels
bug Something isn't working

Comments

@alexpopov
Copy link

Describe the bug
When I try to do Patch Options such as "Move patch into new commit with nothing selected in Custom Patch I get a crash.

To Reproduce
Steps to reproduce the behavior:

This will occur in any repo:

  • enter lazygit
  • go to Commits view
  • enter patch view for some file (enter, enter)
  • Control-P to "View custom patch options"
  • select something like i "Move patch into new commit"
  • observe crash:

Expected behavior
If you repeat these steps at the commit view instead of patch view, you get an error (without crashing):
No patch created yet. To start building a patch, use 'space' on a commit file or enter to add specific lines. Something like this would be useful.

Screenshots

panic: runtime error: index out of range [-1]

goroutine 157 [running]:
github.com/jesseduffield/lazygit/pkg/commands/git_commands.(*RebaseCommands).BeginInteractiveRebaseForCommit(0x14000150300, {0x14000324280, 0x4, 0x140001128f0?}, 0xffffffffffffffff, 0x0)
        github.com/jesseduffield/lazygit/pkg/commands/git_commands/rebase.go:292 +0x278
github.com/jesseduffield/lazygit/pkg/commands/git_commands.(*PatchCommands).MovePatchIntoIndex(0x140002fe330, {0x14000324280?, 0x4, 0x10546a9ac?}, 0xffffffffffffffff, 0x0)
        github.com/jesseduffield/lazygit/pkg/commands/git_commands/patch.go:228 +0xcc
github.com/jesseduffield/lazygit/pkg/gui/controllers.(*CustomPatchOptionsMenuAction).handleMovePatchIntoWorkingTree.func1.1({0x14000030550, 0x14000068900})
        github.com/jesseduffield/lazygit/pkg/gui/controllers/custom_patch_options_menu_action.go:159 +0xe0
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*AppStatusHelper).WithWaitingStatus.func1.1()
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/app_status_helper.go:35 +0x54
github.com/jesseduffield/lazygit/pkg/gui/status.(*StatusManager).WithWaitingStatus(0x1400038e330, {0x105522c4d, 0x8}, 0x140003eaf20)
        github.com/jesseduffield/lazygit/pkg/gui/status/status_manager.go:44 +0x1d8
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*AppStatusHelper).WithWaitingStatus.func1({0x1057e4f70, 0x14000324820})
        github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers/app_status_helper.go:32 +0x94
github.com/jesseduffield/gocui.(*Gui).onWorkerAux(0x0?, 0x0?, {0x1057e4f70?, 0x14000324820?})
        github.com/jesseduffield/gocui@v0.3.1-0.20230723014157-03e858e46144/gui.go:673 +0x6c
github.com/jesseduffield/gocui.(*Gui).OnWorker.func1()
        github.com/jesseduffield/gocui@v0.3.1-0.20230723014157-03e858e46144/gui.go:660 +0x34
created by github.com/jesseduffield/gocui.(*Gui).OnWorker
        github.com/jesseduffield/gocui@v0.3.1-0.20230723014157-03e858e46144/gui.go:659 +0x9c

Version info:
commit=, build date=, build source=homebrew, version=0.39.4, os=darwin, arch=arm64, git version=2.39.2 (Apple Git-143)
git version 2.39.2 (Apple Git-143)

Additional context
N/A

Note: please try updating to the latest version or manually building the latest master to see if the issue still occurs.

@alexpopov alexpopov added the bug Something isn't working label Jul 25, 2023
@jesseduffield
Copy link
Owner

Might have been a recent regression caused by #2800. @alexpopov did you build lazygit from source?

@alexpopov
Copy link
Author

Might have been a recent regression caused by #2800. @alexpopov did you build lazygit from source?

No, I just realized: I got the error from some older build, decided to update in case it fixed it; and did a brew upgrade to get this latest version.

That said, the earlier build I had used may also have been quite recent.

@stefanhaller
Copy link
Collaborator

It's not a regression, it always crashed in this way. The issue is that CustomPatchOptionsMenuAction.Call only checks whether PatchBuilder.Active() is false; but it's true when you are in the patch building view. We also need to check IsEmpty in this case. See #2829 for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants