mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-08 22:36:49 +02:00
Fix possible crash when deleting a branch while filtering is active (#4195)
- **PR Description** Fix #4179.
This commit is contained in:
@ -490,6 +490,8 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele
|
|||||||
self.refreshView(self.c.Contexts().Worktrees)
|
self.refreshView(self.c.Contexts().Worktrees)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.refreshView(self.c.Contexts().Branches)
|
||||||
|
|
||||||
if !keepBranchSelectionIndex && prevSelectedBranch != nil {
|
if !keepBranchSelectionIndex && prevSelectedBranch != nil {
|
||||||
_, idx, found := lo.FindIndexOf(self.c.Contexts().Branches.GetItems(),
|
_, idx, found := lo.FindIndexOf(self.c.Contexts().Branches.GetItems(),
|
||||||
func(b *models.Branch) bool { return b.Name == prevSelectedBranch.Name })
|
func(b *models.Branch) bool { return b.Name == prevSelectedBranch.Name })
|
||||||
@ -498,8 +500,6 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.refreshView(self.c.Contexts().Branches)
|
|
||||||
|
|
||||||
// Need to re-render the commits view because the visualization of local
|
// Need to re-render the commits view because the visualization of local
|
||||||
// branch heads might have changed
|
// branch heads might have changed
|
||||||
self.c.Mutexes().LocalCommitsMutex.Lock()
|
self.c.Mutexes().LocalCommitsMutex.Lock()
|
||||||
|
49
pkg/integration/tests/branch/delete_while_filtering.go
Normal file
49
pkg/integration/tests/branch/delete_while_filtering.go
Normal file
@ -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(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
@ -45,6 +45,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
branch.DeleteMultiple,
|
branch.DeleteMultiple,
|
||||||
branch.DeleteRemoteBranchWithCredentialPrompt,
|
branch.DeleteRemoteBranchWithCredentialPrompt,
|
||||||
branch.DeleteRemoteBranchWithDifferentName,
|
branch.DeleteRemoteBranchWithDifferentName,
|
||||||
|
branch.DeleteWhileFiltering,
|
||||||
branch.DetachedHead,
|
branch.DetachedHead,
|
||||||
branch.NewBranchAutostash,
|
branch.NewBranchAutostash,
|
||||||
branch.NewBranchFromRemoteTrackingDifferentName,
|
branch.NewBranchFromRemoteTrackingDifferentName,
|
||||||
|
Reference in New Issue
Block a user