| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Eric Wong |
| 4 | # |
| 5 | |
| 6 | test_description='git rebase --merge --skip tests' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | |
| 13 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 14 | |
| 15 | # we assume the default git am -3 --skip strategy is tested independently |
| 16 | # and always works :) |
| 17 | |
| 18 | test_expect_success setup ' |
| 19 | echo hello > hello && |
| 20 | git add hello && |
| 21 | git commit -m "hello" && |
| 22 | git branch skip-reference && |
| 23 | git tag hello && |
| 24 | |
| 25 | echo world >> hello && |
| 26 | git commit -a -m "hello world" && |
| 27 | echo goodbye >> hello && |
| 28 | git commit -a -m "goodbye" && |
| 29 | git tag goodbye && |
| 30 | |
| 31 | git checkout --detach && |
| 32 | git checkout HEAD^ . && |
| 33 | test_tick && |
| 34 | git commit -m reverted-goodbye && |
| 35 | git tag reverted-goodbye && |
| 36 | git checkout goodbye && |
| 37 | test_tick && |
| 38 | GIT_AUTHOR_NAME="Another Author" \ |
| 39 | GIT_AUTHOR_EMAIL="another.author@example.com" \ |
| 40 | git commit --amend --no-edit -m amended-goodbye \ |
| 41 | --reset-author && |
| 42 | test_tick && |
| 43 | git tag amended-goodbye && |
| 44 | |
| 45 | git checkout -f skip-reference && |
| 46 | echo moo > hello && |
| 47 | git commit -a -m "we should skip this" && |
| 48 | echo moo > cow && |
| 49 | git add cow && |
| 50 | git commit -m "this should not be skipped" && |
| 51 | git branch pre-rebase skip-reference && |
| 52 | git branch skip-merge skip-reference |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'rebase with git am -3 (default)' ' |
| 56 | test_must_fail git rebase --apply main |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'rebase --skip can not be used with other options' ' |
| 60 | test_must_fail git rebase -v --skip && |
| 61 | test_must_fail git rebase --skip -v |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'rebase --skip with am -3' ' |
| 65 | git rebase --skip |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'rebase moves back to skip-reference' ' |
| 69 | test refs/heads/skip-reference = $(git symbolic-ref HEAD) && |
| 70 | git branch post-rebase && |
| 71 | git reset --hard pre-rebase && |
| 72 | test_must_fail git rebase main && |
| 73 | echo "hello" > hello && |
| 74 | git add hello && |
| 75 | git rebase --continue && |
| 76 | test refs/heads/skip-reference = $(git symbolic-ref HEAD) && |
| 77 | git reset --hard post-rebase |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'checkout skip-merge' 'git checkout -f skip-merge' |
| 81 | |
| 82 | test_expect_success 'rebase with --merge' ' |
| 83 | test_must_fail git rebase --merge main |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'rebase --skip with --merge' ' |
| 87 | git rebase --skip |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'merge and reference trees equal' ' |
| 91 | test -z "$(git diff-tree skip-merge skip-reference)" |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'moved back to branch correctly' ' |
| 95 | test refs/heads/skip-merge = $(git symbolic-ref HEAD) |
| 96 | ' |
| 97 | |
| 98 | test_debug 'gitk --all & sleep 1' |
| 99 | |
| 100 | test_expect_success 'skipping final pick removes .git/MERGE_MSG' ' |
| 101 | test_must_fail git rebase --onto hello reverted-goodbye^ \ |
| 102 | reverted-goodbye && |
| 103 | git rebase --skip && |
| 104 | test_path_is_missing .git/MERGE_MSG |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'correct advice upon picking empty commit' ' |
| 108 | test_when_finished "git rebase --abort" && |
| 109 | test_must_fail git rebase -i --onto goodbye \ |
| 110 | amended-goodbye^ amended-goodbye 2>err && |
| 111 | test_grep "previous cherry-pick is now empty" err && |
| 112 | test_grep "git rebase --skip" err && |
| 113 | test_must_fail git commit && |
| 114 | test_grep "git rebase --skip" err |
| 115 | ' |
| 116 | |
| 117 | test_expect_success 'correct authorship when committing empty pick' ' |
| 118 | test_when_finished "git rebase --abort" && |
| 119 | test_must_fail git rebase -i --onto goodbye \ |
| 120 | amended-goodbye^ amended-goodbye && |
| 121 | git commit --allow-empty && |
| 122 | git log --pretty=format:"%an <%ae>%n%ad%B" -1 amended-goodbye >expect && |
| 123 | git log --pretty=format:"%an <%ae>%n%ad%B" -1 HEAD >actual && |
| 124 | test_cmp expect actual |
| 125 | ' |
| 126 | |
| 127 | test_expect_success 'correct advice upon rewording empty commit' ' |
| 128 | test_when_finished "git rebase --abort" && |
| 129 | ( |
| 130 | set_fake_editor && |
| 131 | test_must_fail env FAKE_LINES="reword 1" git rebase -i \ |
| 132 | --onto goodbye amended-goodbye^ amended-goodbye 2>err |
| 133 | ) && |
| 134 | test_grep "previous cherry-pick is now empty" err && |
| 135 | test_grep "git rebase --skip" err && |
| 136 | test_must_fail git commit && |
| 137 | test_grep "git rebase --skip" err |
| 138 | ' |
| 139 | |
| 140 | test_expect_success 'correct advice upon editing empty commit' ' |
| 141 | test_when_finished "git rebase --abort" && |
| 142 | ( |
| 143 | set_fake_editor && |
| 144 | test_must_fail env FAKE_LINES="edit 1" git rebase -i \ |
| 145 | --onto goodbye amended-goodbye^ amended-goodbye 2>err |
| 146 | ) && |
| 147 | test_grep "previous cherry-pick is now empty" err && |
| 148 | test_grep "git rebase --skip" err && |
| 149 | test_must_fail git commit && |
| 150 | test_grep "git rebase --skip" err |
| 151 | ' |
| 152 | |
| 153 | test_expect_success 'correct advice upon cherry-picking an empty commit during a rebase' ' |
| 154 | test_when_finished "git rebase --abort" && |
| 155 | ( |
| 156 | set_fake_editor && |
| 157 | test_must_fail env FAKE_LINES="1 exec_git_cherry-pick_amended-goodbye" \ |
| 158 | git rebase -i goodbye^ goodbye 2>err |
| 159 | ) && |
| 160 | test_grep "previous cherry-pick is now empty" err && |
| 161 | test_grep "git cherry-pick --skip" err && |
| 162 | test_must_fail git commit 2>err && |
| 163 | test_grep "git cherry-pick --skip" err |
| 164 | ' |
| 165 | |
| 166 | test_expect_success 'correct advice upon multi cherry-pick picking an empty commit during a rebase' ' |
| 167 | test_when_finished "git rebase --abort" && |
| 168 | ( |
| 169 | set_fake_editor && |
| 170 | test_must_fail env FAKE_LINES="1 exec_git_cherry-pick_goodbye_amended-goodbye" \ |
| 171 | git rebase -i goodbye^^ goodbye 2>err |
| 172 | ) && |
| 173 | test_grep "previous cherry-pick is now empty" err && |
| 174 | test_grep "git cherry-pick --skip" err && |
| 175 | test_must_fail git commit 2>err && |
| 176 | test_grep "git cherry-pick --skip" err |
| 177 | ' |
| 178 | |
| 179 | test_expect_success 'fixup that empties commit fails' ' |
| 180 | test_when_finished "git rebase --abort" && |
| 181 | ( |
| 182 | set_fake_editor && |
| 183 | test_must_fail env FAKE_LINES="1 fixup 2" git rebase -i \ |
| 184 | goodbye^ reverted-goodbye |
| 185 | ) |
| 186 | ' |
| 187 | |
| 188 | test_expect_success 'squash that empties commit fails' ' |
| 189 | test_when_finished "git rebase --abort" && |
| 190 | ( |
| 191 | set_fake_editor && |
| 192 | test_must_fail env FAKE_LINES="1 squash 2" git rebase -i \ |
| 193 | goodbye^ reverted-goodbye |
| 194 | ) |
| 195 | ' |
| 196 | |
| 197 | # Must be the last test in this file |
| 198 | test_expect_success '$EDITOR and friends are unchanged' ' |
| 199 | test_editor_unchanged |
| 200 | ' |
| 201 | |
| 202 | test_done |