Skip to content

Commit ea16e0f

Browse files
committed
fixup! Make fixup helper ignore other fixup commits when trying to find base commit
1 parent 7f95ff7 commit ea16e0f

File tree

4 files changed

+72
-11
lines changed

4 files changed

+72
-11
lines changed

pkg/gui/controllers/helpers/fixup_helper.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,20 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
128128
return fmt.Errorf("%s\n\n%s", message, subjects)
129129
}
130130
// There is only a single non fixup commit found. Present it with a Confirmation dialog.
131-
_, index, _ := self.findCommit(commits, non_fixup_commits[0].Hash())
131+
found_commit := non_fixup_commits[0]
132+
all_fixup_for_found_commit := lo.EveryBy(unmerged_commits, func(c *models.Commit) bool {
133+
if c == found_commit {
134+
return true
135+
}
136+
fixup_subject := c.Name
137+
fixup_subject = strings.TrimPrefix(fixup_subject, "fixup! ")
138+
fixup_subject = strings.TrimPrefix(fixup_subject, "squash! ")
139+
fixup_subject = strings.TrimPrefix(fixup_subject, "amend! ")
140+
return strings.HasPrefix(found_commit.Name, fixup_subject)
141+
})
142+
_, index, _ := self.findCommit(commits, found_commit.Hash())
132143

133-
return self.c.ConfirmIf(true, types.ConfirmOpts{
144+
return self.c.ConfirmIf(!all_fixup_for_found_commit, types.ConfirmOpts{
134145
Title: self.c.Tr.FindBaseCommitForFixup,
135146
Prompt: fmt.Sprintf("%s\n\n%s", self.c.Tr.MultipleBaseCommitsOnlyOneNonFixup, subjects),
136147
HandleConfirm: self.getHandlerToStageAndSelectIndex(hasStagedChanges, index),

pkg/integration/tests/commit/find_base_commit_for_fixup_ignore_fixup_commits.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ var FindBaseCommitForFixupIgnoreFixupCommits = NewIntegrationTest(NewIntegration
3636
t.Views().Files().
3737
Focus().
3838
Press(keys.Files.FindBaseCommitForFixup)
39-
t.ExpectPopup().
40-
Confirmation().
41-
Title(Equals("Find base commit for fixup")).
42-
Content(
43-
Contains("all but one of them were fixup commits").
44-
Contains("3rd commit").
45-
Contains("fixup! 3rd commit"),
46-
).
47-
Confirm()
4839
t.Views().Commits().
4940
IsFocused().
5041
Lines(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package commit
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var FindBaseCommitForFixupIgnoreFixupCommitsWarnForOther = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Finds the base commit to create a fixup for, disregarding changes to a commit that is already on master",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.
15+
EmptyCommit("1st commit").
16+
CreateFileAndAdd("file", "file1 content line 1\nfile1 content line 2\n").
17+
Commit("2nd commit").
18+
NewBranch("mybranch").
19+
UpdateFileAndAdd("file", "file1 changed content line 1\nfile1 changed content line 2\n").
20+
Commit("3rd commit").
21+
EmptyCommit("4th commit").
22+
UpdateFileAndAdd("file", "file1 1st fixup content line 1\nfile1 changed content line 2\n").
23+
Commit("fixup! some other commit").
24+
UpdateFile("file", "file1 2nd fixup content line 1\nfile1 2nd fixup content line 2\n")
25+
},
26+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
27+
t.Views().Commits().
28+
Lines(
29+
Contains("fixup! some other commit").IsSelected(),
30+
Contains("4th commit"),
31+
Contains("3rd commit"),
32+
Contains("2nd commit"),
33+
Contains("1st commit"),
34+
)
35+
36+
t.Views().Files().
37+
Focus().
38+
Press(keys.Files.FindBaseCommitForFixup)
39+
t.ExpectPopup().
40+
Confirmation().
41+
Title(Equals("Find base commit for fixup")).
42+
Content(
43+
Contains("all but one of them were fixup commits").
44+
Contains("3rd commit").
45+
Contains("fixup! some other commit"),
46+
).
47+
Confirm()
48+
t.Views().Commits().
49+
IsFocused().
50+
Lines(
51+
Contains("fixup! some other commit"),
52+
Contains("4th commit"),
53+
Contains("3rd commit").IsSelected(),
54+
Contains("2nd commit"),
55+
Contains("1st commit"),
56+
)
57+
},
58+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var tests = []*components.IntegrationTest{
132132
commit.FindBaseCommitForFixup,
133133
commit.FindBaseCommitForFixupDisregardMainBranch,
134134
commit.FindBaseCommitForFixupIgnoreFixupCommits,
135+
commit.FindBaseCommitForFixupIgnoreFixupCommitsWarnForOther,
135136
commit.FindBaseCommitForFixupOnlyAddedLines,
136137
commit.FindBaseCommitForFixupWarningForAddedLines,
137138
commit.Highlight,

0 commit comments

Comments
 (0)