Skip to content

Commit 26f2c02

Browse files
authored
Allow rewording or dropping commits in filtering mode (#4756)
- **PR Description** Rewording or dropping commits was disabled when filtering commits by path or author. This used to be necessary a long time ago for technical reasons, but these reasons went away with the merge of #2552, so enable them now. Technically we could enable a few more, but I chose not to because some might be surprising or confusing in filtering mode. For example, creating a fixup commit would work (shift-F), but the newly created commit might not show up if it doesn't match the filter. Similarly, pressing `f` to fixup a commit into its parent would work, but that parent commit might not be visible, so users might expect to be fixing up into the next visible commit. Fixes #2554.
2 parents 96480ed + 52be696 commit 26f2c02

File tree

6 files changed

+130
-39
lines changed

6 files changed

+130
-39
lines changed

pkg/gui/controllers/local_commits_controller.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ func NewLocalCommitsController(
5555
func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
5656
editCommitKey := opts.Config.Universal.Edit
5757

58-
outsideFilterModeBindings := []*types.Binding{
58+
bindings := []*types.Binding{
5959
{
6060
Key: opts.GetKey(opts.Config.Commits.SquashDown),
61-
Handler: self.withItemsRange(self.squashDown),
61+
Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.squashDown)),
6262
GetDisabledReason: self.require(
6363
self.itemRangeSelected(
6464
self.midRebaseCommandEnabled,
@@ -71,7 +71,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
7171
},
7272
{
7373
Key: opts.GetKey(opts.Config.Commits.MarkCommitAsFixup),
74-
Handler: self.withItemsRange(self.fixup),
74+
Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.fixup)),
7575
GetDisabledReason: self.require(
7676
self.itemRangeSelected(
7777
self.midRebaseCommandEnabled,
@@ -115,7 +115,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
115115
},
116116
{
117117
Key: opts.GetKey(editCommitKey),
118-
Handler: self.withItemsRange(self.edit),
118+
Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.edit)),
119119
GetDisabledReason: self.require(
120120
self.itemRangeSelected(self.midRebaseCommandEnabled),
121121
),
@@ -129,7 +129,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
129129
// we're calling it 'quick-start interactive rebase' to differentiate it from
130130
// when you manually select the base commit.
131131
Key: opts.GetKey(opts.Config.Commits.StartInteractiveRebase),
132-
Handler: self.quickStartInteractiveRebase,
132+
Handler: opts.Guards.OutsideFilterMode(self.quickStartInteractiveRebase),
133133
GetDisabledReason: self.require(self.notMidRebase(self.c.Tr.AlreadyRebasing), self.canFindCommitForQuickStart),
134134
Description: self.c.Tr.QuickStartInteractiveRebase,
135135
Tooltip: utils.ResolvePlaceholderString(self.c.Tr.QuickStartInteractiveRebaseTooltip, map[string]string{
@@ -138,7 +138,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
138138
},
139139
{
140140
Key: opts.GetKey(opts.Config.Commits.PickCommit),
141-
Handler: self.withItems(self.pick),
141+
Handler: opts.Guards.OutsideFilterMode(self.withItems(self.pick)),
142142
GetDisabledReason: self.require(
143143
self.itemRangeSelected(self.pickEnabled),
144144
),
@@ -147,7 +147,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
147147
},
148148
{
149149
Key: opts.GetKey(opts.Config.Commits.CreateFixupCommit),
150-
Handler: self.withItem(self.createFixupCommit),
150+
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.createFixupCommit)),
151151
GetDisabledReason: self.require(self.singleItemSelected()),
152152
Description: self.c.Tr.CreateFixupCommit,
153153
Tooltip: utils.ResolvePlaceholderString(
@@ -159,7 +159,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
159159
},
160160
{
161161
Key: opts.GetKey(opts.Config.Commits.SquashAboveCommits),
162-
Handler: self.squashFixupCommits,
162+
Handler: opts.Guards.OutsideFilterMode(self.squashFixupCommits),
163163
GetDisabledReason: self.require(
164164
self.notMidRebase(self.c.Tr.AlreadyRebasing),
165165
),
@@ -169,7 +169,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
169169
},
170170
{
171171
Key: opts.GetKey(opts.Config.Commits.MoveDownCommit),
172-
Handler: self.withItemsRange(self.moveDown),
172+
Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.moveDown)),
173173
GetDisabledReason: self.require(self.itemRangeSelected(
174174
self.midRebaseMoveCommandEnabled,
175175
self.canMoveDown,
@@ -178,7 +178,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
178178
},
179179
{
180180
Key: opts.GetKey(opts.Config.Commits.MoveUpCommit),
181-
Handler: self.withItemsRange(self.moveUp),
181+
Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.moveUp)),
182182
GetDisabledReason: self.require(self.itemRangeSelected(
183183
self.midRebaseMoveCommandEnabled,
184184
self.canMoveUp,
@@ -187,25 +187,18 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
187187
},
188188
{
189189
Key: opts.GetKey(opts.Config.Commits.PasteCommits),
190-
Handler: self.paste,
190+
Handler: opts.Guards.OutsideFilterMode(self.paste),
191191
GetDisabledReason: self.require(self.canPaste),
192192
Description: self.c.Tr.PasteCommits,
193193
DisplayStyle: &style.FgCyan,
194194
},
195195
{
196196
Key: opts.GetKey(opts.Config.Commits.MarkCommitAsBaseForRebase),
197-
Handler: self.withItem(self.markAsBaseCommit),
197+
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.markAsBaseCommit)),
198198
GetDisabledReason: self.require(self.singleItemSelected()),
199199
Description: self.c.Tr.MarkAsBaseCommit,
200200
Tooltip: self.c.Tr.MarkAsBaseCommitTooltip,
201201
},
202-
}
203-
204-
for _, binding := range outsideFilterModeBindings {
205-
binding.Handler = opts.Guards.OutsideFilterMode(binding.Handler)
206-
}
207-
208-
bindings := append(outsideFilterModeBindings, []*types.Binding{
209202
// overriding this navigation keybinding because we might need to load
210203
// more commits on demand
211204
{
@@ -251,7 +244,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
251244
Tooltip: self.c.Tr.OpenLogMenuTooltip,
252245
OpensMenu: true,
253246
},
254-
}...)
247+
}
255248

256249
return bindings
257250
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package filter_by_path
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var DropCommitInFilteringMode = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Filter commits by file path, then drop a commit",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
commonSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
filterByFilterFile(t, keys)
19+
20+
t.Views().Commits().
21+
IsFocused().
22+
Lines(
23+
Contains(`both files`).IsSelected(),
24+
Contains(`only filterFile`),
25+
).
26+
Press(keys.Universal.Remove).
27+
Tap(func() {
28+
t.ExpectPopup().Confirmation().
29+
Title(Equals("Drop commit")).
30+
Content(Equals("Are you sure you want to drop the selected commit(s)?")).
31+
Confirm()
32+
}).
33+
Lines(
34+
Contains(`only filterFile`).IsSelected(),
35+
).
36+
Press(keys.Universal.Return).
37+
Lines(
38+
Contains(`none of the two`),
39+
Contains(`only otherFile`),
40+
Contains(`only filterFile`).IsSelected(),
41+
)
42+
},
43+
})

pkg/integration/tests/filter_by_path/keep_same_commit_selected_on_exit.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,10 @@ var KeepSameCommitSelectedOnExit = NewIntegrationTest(NewIntegrationTestArgs{
1515
commonSetup(shell)
1616
},
1717
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18-
t.Views().Commits().
19-
Focus().
20-
Lines(
21-
Contains(`none of the two`).IsSelected(),
22-
Contains(`both files`),
23-
Contains(`only otherFile`),
24-
Contains(`only filterFile`),
25-
).Press(keys.Universal.FilteringMenu).
26-
Tap(func() {
27-
t.ExpectPopup().Menu().
28-
Title(Equals("Filtering")).
29-
Select(Contains("Enter path to filter by")).
30-
Confirm()
18+
filterByFilterFile(t, keys)
3119

32-
t.ExpectPopup().Prompt().
33-
Title(Equals("Enter path:")).
34-
Type("filterF").
35-
SuggestionLines(Equals("filterFile")).
36-
ConfirmFirstSuggestion()
37-
}).
20+
t.Views().Commits().
21+
IsFocused().
3822
Lines(
3923
Contains(`both files`).IsSelected(),
4024
Contains(`only filterFile`),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package filter_by_path
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var RewordCommitInFilteringMode = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Filter commits by file path, then reword a commit",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
commonSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
filterByFilterFile(t, keys)
19+
20+
t.Views().Commits().
21+
IsFocused().
22+
Lines(
23+
Contains(`both files`).IsSelected(),
24+
Contains(`only filterFile`),
25+
).
26+
SelectNextItem().
27+
Press(keys.Commits.RenameCommit).
28+
Tap(func() {
29+
t.ExpectPopup().CommitMessagePanel().
30+
Clear().
31+
Type("new message").
32+
Confirm()
33+
}).
34+
Lines(
35+
Contains(`both files`),
36+
Contains(`new message`).IsSelected(),
37+
).
38+
Press(keys.Universal.Return).
39+
Lines(
40+
Contains(`none of the two`),
41+
Contains(`both files`),
42+
Contains(`only otherFile`),
43+
Contains(`new message`).IsSelected(),
44+
)
45+
},
46+
})

pkg/integration/tests/filter_by_path/shared.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package filter_by_path
22

33
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
45
. "github.com/jesseduffield/lazygit/pkg/integration/components"
56
)
67

@@ -17,6 +18,28 @@ func commonSetup(shell *Shell) {
1718
shell.EmptyCommit("none of the two")
1819
}
1920

21+
func filterByFilterFile(t *TestDriver, keys config.KeybindingConfig) {
22+
t.Views().Commits().
23+
Focus().
24+
Lines(
25+
Contains(`none of the two`).IsSelected(),
26+
Contains(`both files`),
27+
Contains(`only otherFile`),
28+
Contains(`only filterFile`),
29+
).
30+
Press(keys.Universal.FilteringMenu)
31+
32+
t.ExpectPopup().Menu().
33+
Title(Equals("Filtering")).
34+
Select(Contains("Enter path to filter by")).
35+
Confirm()
36+
t.ExpectPopup().Prompt().
37+
Title(Equals("Enter path:")).
38+
Type("filterF").
39+
SuggestionLines(Equals("filterFile")).
40+
ConfirmFirstSuggestion()
41+
}
42+
2043
func postFilterTest(t *TestDriver) {
2144
t.Views().Information().Content(Contains("Filtering by 'filterFile'"))
2245

pkg/integration/tests/test_list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ var tests = []*components.IntegrationTest{
233233
filter_by_author.SelectAuthor,
234234
filter_by_author.TypeAuthor,
235235
filter_by_path.CliArg,
236+
filter_by_path.DropCommitInFilteringMode,
236237
filter_by_path.KeepSameCommitSelectedOnExit,
238+
filter_by_path.RewordCommitInFilteringMode,
237239
filter_by_path.SelectFile,
238240
filter_by_path.ShowDiffsForRenamedFile,
239241
filter_by_path.TypeFile,

0 commit comments

Comments
 (0)