Skip to content

Commit 52be696

Browse files
committed
Allow rewording and dropping commits in filtering mode
There's no reason not to allow these. 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.
1 parent bc936e8 commit 52be696

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

pkg/gui/controllers/local_commits_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
8484
},
8585
{
8686
Key: opts.GetKey(opts.Config.Commits.RenameCommit),
87-
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.reword)),
87+
Handler: self.withItem(self.reword),
8888
GetDisabledReason: self.require(
8989
self.singleItemSelected(self.rewordEnabled),
9090
),
@@ -95,15 +95,15 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
9595
},
9696
{
9797
Key: opts.GetKey(opts.Config.Commits.RenameCommitWithEditor),
98-
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.rewordEditor)),
98+
Handler: self.withItem(self.rewordEditor),
9999
GetDisabledReason: self.require(
100100
self.singleItemSelected(self.rewordEnabled),
101101
),
102102
Description: self.c.Tr.RewordCommitEditor,
103103
},
104104
{
105105
Key: opts.GetKey(opts.Config.Universal.Remove),
106-
Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.drop)),
106+
Handler: self.withItemsRange(self.drop),
107107
GetDisabledReason: self.require(
108108
self.itemRangeSelected(
109109
self.canDropCommits,
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+
})
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/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)