|
| 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 CherryPickCommitThatBecomesEmpty = NewIntegrationTest(NewIntegrationTestArgs{ |
| 9 | + Description: "Cherry-pick a commit that becomes empty at the destination", |
| 10 | + ExtraCmdArgs: []string{}, |
| 11 | + Skip: false, |
| 12 | + SetupConfig: func(config *config.AppConfig) {}, |
| 13 | + SetupRepo: func(shell *Shell) { |
| 14 | + shell. |
| 15 | + EmptyCommit("base"). |
| 16 | + CreateFileAndAdd("file1", "change 1\n"). |
| 17 | + CreateFileAndAdd("file2", "change 2\n"). |
| 18 | + Commit("two changes in one commit"). |
| 19 | + NewBranchFrom("branch", "HEAD^"). |
| 20 | + CreateFileAndAdd("file1", "change 1\n"). |
| 21 | + Commit("single change"). |
| 22 | + CreateFileAndAdd("file3", "change 3\n"). |
| 23 | + Commit("unrelated change"). |
| 24 | + Checkout("master") |
| 25 | + }, |
| 26 | + Run: func(t *TestDriver, keys config.KeybindingConfig) { |
| 27 | + t.Views().Branches(). |
| 28 | + Focus(). |
| 29 | + Lines( |
| 30 | + Contains("master").IsSelected(), |
| 31 | + Contains("branch"), |
| 32 | + ). |
| 33 | + SelectNextItem(). |
| 34 | + PressEnter() |
| 35 | + |
| 36 | + t.Views().SubCommits(). |
| 37 | + IsFocused(). |
| 38 | + Lines( |
| 39 | + Contains("unrelated change").IsSelected(), |
| 40 | + Contains("single change"), |
| 41 | + Contains("base"), |
| 42 | + ). |
| 43 | + Press(keys.Universal.RangeSelectDown). |
| 44 | + Press(keys.Commits.CherryPickCopy). |
| 45 | + Tap(func() { |
| 46 | + t.Views().Information().Content(Contains("2 commits copied")) |
| 47 | + }) |
| 48 | + |
| 49 | + t.Views().Commits(). |
| 50 | + Focus(). |
| 51 | + Lines( |
| 52 | + Contains("two changes in one commit").IsSelected(), |
| 53 | + Contains("base"), |
| 54 | + ). |
| 55 | + Press(keys.Commits.PasteCommits). |
| 56 | + Tap(func() { |
| 57 | + t.ExpectPopup().Alert(). |
| 58 | + Title(Equals("Cherry-pick")). |
| 59 | + Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")). |
| 60 | + Confirm() |
| 61 | + }) |
| 62 | + |
| 63 | + if t.Git().Version().IsAtLeast(2, 45, 0) { |
| 64 | + t.Views().Commits(). |
| 65 | + Lines( |
| 66 | + Contains("unrelated change"), |
| 67 | + Contains("single change"), |
| 68 | + Contains("two changes in one commit").IsSelected(), |
| 69 | + Contains("base"), |
| 70 | + ). |
| 71 | + SelectPreviousItem() |
| 72 | + |
| 73 | + // Cherry-picked commit is empty |
| 74 | + t.Views().Main().Content(DoesNotContain("diff --git")) |
| 75 | + } else { |
| 76 | + t.Views().Commits(). |
| 77 | + // We have a bug with how the selection is updated in this case; normally you would |
| 78 | + // expect the "two changes in one commit" commit to be selected because it was |
| 79 | + // selected before pasting, and we try to maintain that selection. This is broken |
| 80 | + // for two reasons: |
| 81 | + // 1. We increment the selected line index after pasting by the number of pasted |
| 82 | + // commits; this is wrong because we skipped the commit that became empty. So |
| 83 | + // according to this bug, the "base" commit should be selected. |
| 84 | + // 2. We only update the selected line index after pasting if the currently selected |
| 85 | + // commit is not a rebase TODO commit, on the assumption that if it is, we are in a |
| 86 | + // rebase and the cherry-picked commits end up below the selection. In this case, |
| 87 | + // however, we still think we are cherry-picking because the final refresh after the |
| 88 | + // CheckMergeOrRebase in CherryPickHelper.Paste is async and hasn't completed yet; |
| 89 | + // so the "unrelated change" still has a "pick" action. |
| 90 | + // |
| 91 | + // Since this only happens for older git versions, we don't bother fixing it. |
| 92 | + Lines( |
| 93 | + Contains("unrelated change").IsSelected(), |
| 94 | + Contains("two changes in one commit"), |
| 95 | + Contains("base"), |
| 96 | + ) |
| 97 | + } |
| 98 | + }, |
| 99 | +}) |
0 commit comments