Skip to content

Commit 108054e

Browse files
committed
Allow cherry-picking merge commits
Now that we use git cherry-pick to implement it, there's no reason not to.
1 parent 27825eb commit 108054e

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

Diff for: pkg/gui/controllers/basic_commits_controller.go

-4
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,6 @@ func (self *BasicCommitsController) canCopyCommits(selectedCommits []*models.Com
366366
if commit.Hash == "" {
367367
return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickNonCommit, ShowErrorInPanel: true}
368368
}
369-
370-
if commit.IsMerge() {
371-
return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickMergeCommit, ShowErrorInPanel: true}
372-
}
373369
}
374370

375371
return nil
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package cherry_pick
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var CherryPickMerge = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Cherry pick a merge commit",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.
15+
EmptyCommit("base").
16+
NewBranch("first-branch").
17+
NewBranch("second-branch").
18+
Checkout("first-branch").
19+
Checkout("second-branch").
20+
CreateFileAndAdd("file1.txt", "content").
21+
Commit("one").
22+
CreateFileAndAdd("file2.txt", "content").
23+
Commit("two").
24+
Checkout("master").
25+
Merge("second-branch").
26+
Checkout("first-branch")
27+
},
28+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
29+
t.Views().Branches().
30+
Focus().
31+
Lines(
32+
Contains("first-branch"),
33+
Contains("master"),
34+
Contains("second-branch"),
35+
).
36+
SelectNextItem().
37+
PressEnter()
38+
39+
t.Views().SubCommits().
40+
IsFocused().
41+
Lines(
42+
Contains("⏣─╮ Merge branch 'second-branch'").IsSelected(),
43+
Contains("│ ◯ two"),
44+
Contains("│ ◯ one"),
45+
Contains("◯ ╯ base"),
46+
).
47+
// copy the merge commit
48+
Press(keys.Commits.CherryPickCopy)
49+
50+
t.Views().Information().Content(Contains("1 commit copied"))
51+
52+
t.Views().Commits().
53+
Focus().
54+
Lines(
55+
Contains("base").IsSelected(),
56+
).
57+
Press(keys.Commits.PasteCommits).
58+
Tap(func() {
59+
t.ExpectPopup().Alert().
60+
Title(Equals("Cherry-pick")).
61+
Content(Contains("Are you sure you want to cherry-pick the 1 copied commit(s) onto this branch?")).
62+
Confirm()
63+
}).
64+
Tap(func() {
65+
t.Views().Information().Content(DoesNotContain("commit copied"))
66+
}).
67+
Lines(
68+
Contains("Merge branch 'second-branch'").IsSelected(),
69+
Contains("base"),
70+
)
71+
72+
t.Views().Main().ContainsLines(
73+
Contains("Merge branch 'second-branch'"),
74+
Contains("---"),
75+
Contains("file1.txt | 1 +"),
76+
Contains("file2.txt | 1 +"),
77+
Contains("2 files changed, 2 insertions(+)"),
78+
)
79+
},
80+
})

Diff for: pkg/integration/tests/test_list.go

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ var tests = []*components.IntegrationTest{
8282
cherry_pick.CherryPick,
8383
cherry_pick.CherryPickConflicts,
8484
cherry_pick.CherryPickDuringRebase,
85+
cherry_pick.CherryPickMerge,
8586
cherry_pick.CherryPickRange,
8687
commit.AddCoAuthor,
8788
commit.AddCoAuthorRange,

0 commit comments

Comments
 (0)