-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix possible crash when deleting a branch while filtering is active
The code that tries to reselect the same branch again uses GetItems, which in case of filtering is the filtered list. After replacing the branches slice with a new one, the filtered list is no longer up to date, so we must reapply the filter before working with it. It so happens that refreshView does that, so simply call that before setting the selection again; I don't think the order matters in this case. Otherwise we'd have to insert another call to ReApplyFilter before the call to GetItems, which we can avoid this way. Note that this doesn't actually make anything work better in the case of deleting a branch, since we can't reselect the deleted branch anyway of course. But it avoids a possible crash if the branch that was deleted was the last one in the unfiltered list.
- Loading branch information
1 parent
49f8dc2
commit c20badb
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package branch | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
// Regression test for deleting the last branch in the unfiltered list while | ||
// filtering is on. This used to cause a segfault. | ||
var DeleteWhileFiltering = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Delete a local branch while there's a filter in the branches panel", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) { | ||
config.GetAppState().LocalBranchSortOrder = "alphabetic" | ||
}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.EmptyCommit("one") | ||
shell.NewBranch("branch1") | ||
shell.NewBranch("branch2") | ||
shell.Checkout("master") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Branches(). | ||
Focus(). | ||
Lines( | ||
Contains("master").IsSelected(), | ||
Contains("branch1"), | ||
Contains("branch2"), | ||
). | ||
FilterOrSearch("branch"). | ||
Lines( | ||
Contains("branch1").IsSelected(), | ||
Contains("branch2"), | ||
). | ||
SelectNextItem(). | ||
Press(keys.Universal.Remove). | ||
Tap(func() { | ||
t.ExpectPopup(). | ||
Menu(). | ||
Title(Equals("Delete branch 'branch2'?")). | ||
Select(Contains("Delete local branch")). | ||
Confirm() | ||
}). | ||
Lines( | ||
Contains("branch1").IsSelected(), | ||
) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters