Skip to content

Fix panic in custom patch actions when the patch's commit is no longer in the view - #5865

Open
faizanmohiuddin482 wants to merge 1 commit into
jesseduffield:masterfrom
faizanmohiuddin482:fix/patch-move-crash-when-commit-not-in-branch
Open

Fix panic in custom patch actions when the patch's commit is no longer in the view#5865
faizanmohiuddin482 wants to merge 1 commit into
jesseduffield:masterfrom
faizanmohiuddin482:fix/patch-move-crash-when-commit-not-in-branch

Conversation

@faizanmohiuddin482

Copy link
Copy Markdown

Fixes #5802.

When you build a custom patch from a commit and then check out a branch that doesn't contain that commit, getPatchCommitIndex() returns -1, which was passed straight into commits[commitIndex], causing panic: runtime error: index out of range [-1].

The reported repro is "Move patch out into index", but the same -1 reaches all five custom-patch menu actions (delete from commit, move to selected commit, move into index, and both pull-into-new-commit actions).

Fix

getPatchCommitIndex() now returns an error when the patch's commit can't be found in the current commits list, and each action surfaces it as a friendly message instead of crashing:

Cannot find the commit this custom patch was created from in the current commits list. This can happen after switching branches; recreate the patch to continue.

Test

Added an integration test (MoveToIndexWhenCommitNotInCurrentBranch) that builds a patch, checks out a branch without the source commit, and moves the patch into the index. It panics with index out of range [-1] on master and passes with this change.

Note

PatchBuildingController.getPatchCommitIndex() has the same return -1 pattern and could be guarded similarly; I kept this PR scoped to the reported crash, but happy to cover it too if you'd like.

When a custom patch is built from a commit and you then check out a branch
that doesn't contain that commit, getPatchCommitIndex() returns -1, which was
passed straight into commits[commitIndex], panicking with 'index out of range
[-1]' (jesseduffield#5802). This affected all five custom-patch menu actions.

Make getPatchCommitIndex() return an error when the patch's commit is no longer
present, and have each action surface it as a friendly message instead of
crashing. Add an integration test reproducing the scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when using custom patch after switching branches

1 participant