3 # Copyright (c) 2006 Eric Wong
6 test_description='git rebase --merge --skip tests'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 . "$TEST_DIRECTORY"/lib-rebase.sh
15 # we assume the default git am -3 --skip strategy is tested independently
18 test_expect_success setup '
21 git commit -m "hello" &&
22 git branch skip-reference &&
24 echo world >> hello &&
25 git commit -a -m "hello world" &&
26 echo goodbye >> hello &&
27 git commit -a -m "goodbye" &&
30 git checkout --detach &&
31 git checkout HEAD^ . &&
33 git commit -m reverted-goodbye &&
34 git tag reverted-goodbye &&
35 git checkout goodbye &&
37 GIT_AUTHOR_NAME="Another Author" \
38 GIT_AUTHOR_EMAIL="another.author@example.com" \
39 git commit --amend --no-edit -m amended-goodbye &&
41 git tag amended-goodbye &&
43 git checkout -f skip-reference &&
45 git commit -a -m "we should skip this" &&
48 git commit -m "this should not be skipped" &&
49 git branch pre-rebase skip-reference &&
50 git branch skip-merge skip-reference
53 test_expect_success 'rebase with git am -3 (default)' '
54 test_must_fail git rebase main
57 test_expect_success 'rebase --skip can not be used with other options' '
58 test_must_fail git rebase -v --skip &&
59 test_must_fail git rebase --skip -v
62 test_expect_success 'rebase --skip with am -3' '
66 test_expect_success 'rebase moves back to skip-reference' '
67 test refs/heads/skip-reference = $(git symbolic-ref HEAD) &&
68 git branch post-rebase &&
69 git reset --hard pre-rebase &&
70 test_must_fail git rebase main &&
71 echo "hello" > hello &&
73 git rebase --continue &&
74 test refs/heads/skip-reference = $(git symbolic-ref HEAD) &&
75 git reset --hard post-rebase
78 test_expect_success 'checkout skip-merge' 'git checkout -f skip-merge'
80 test_expect_success 'rebase with --merge' '
81 test_must_fail git rebase --merge main
84 test_expect_success 'rebase --skip with --merge' '
88 test_expect_success 'merge and reference trees equal' '
89 test -z "$(git diff-tree skip-merge skip-reference)"
92 test_expect_success 'moved back to branch correctly' '
93 test refs/heads/skip-merge = $(git symbolic-ref HEAD)
96 test_debug 'gitk --all & sleep 1'
98 test_expect_success 'correct advice upon picking empty commit' '
99 test_when_finished "git rebase --abort" &&
100 test_must_fail git rebase -i --onto goodbye \
101 amended-goodbye^ amended-goodbye 2>err &&
102 test_i18ngrep "previous cherry-pick is now empty" err &&
103 test_i18ngrep "git rebase --skip" err &&
104 test_must_fail git commit &&
105 test_i18ngrep "git rebase --skip" err
108 test_expect_success 'correct authorship when committing empty pick' '
109 test_when_finished "git rebase --abort" &&
110 test_must_fail git rebase -i --onto goodbye \
111 amended-goodbye^ amended-goodbye &&
112 git commit --allow-empty &&
113 git log --pretty=format:"%an <%ae>%n%ad%B" -1 amended-goodbye >expect &&
114 git log --pretty=format:"%an <%ae>%n%ad%B" -1 HEAD >actual &&
115 test_cmp expect actual
118 test_expect_success 'correct advice upon rewording empty commit' '
119 test_when_finished "git rebase --abort" &&
122 test_must_fail env FAKE_LINES="reword 1" git rebase -i \
123 --onto goodbye amended-goodbye^ amended-goodbye 2>err
125 test_i18ngrep "previous cherry-pick is now empty" err &&
126 test_i18ngrep "git rebase --skip" err &&
127 test_must_fail git commit &&
128 test_i18ngrep "git rebase --skip" err
131 test_expect_success 'correct advice upon editing empty commit' '
132 test_when_finished "git rebase --abort" &&
135 test_must_fail env FAKE_LINES="edit 1" git rebase -i \
136 --onto goodbye amended-goodbye^ amended-goodbye 2>err
138 test_i18ngrep "previous cherry-pick is now empty" err &&
139 test_i18ngrep "git rebase --skip" err &&
140 test_must_fail git commit &&
141 test_i18ngrep "git rebase --skip" err
144 test_expect_success 'correct advice upon cherry-picking an empty commit during a rebase' '
145 test_when_finished "git rebase --abort" &&
148 test_must_fail env FAKE_LINES="1 exec_git_cherry-pick_amended-goodbye" \
149 git rebase -i goodbye^ goodbye 2>err
151 test_i18ngrep "previous cherry-pick is now empty" err &&
152 test_i18ngrep "git cherry-pick --skip" err &&
153 test_must_fail git commit 2>err &&
154 test_i18ngrep "git cherry-pick --skip" err
157 test_expect_success 'correct advice upon multi cherry-pick picking an empty commit during a rebase' '
158 test_when_finished "git rebase --abort" &&
161 test_must_fail env FAKE_LINES="1 exec_git_cherry-pick_goodbye_amended-goodbye" \
162 git rebase -i goodbye^^ goodbye 2>err
164 test_i18ngrep "previous cherry-pick is now empty" err &&
165 test_i18ngrep "git cherry-pick --skip" err &&
166 test_must_fail git commit 2>err &&
167 test_i18ngrep "git cherry-pick --skip" err
170 test_expect_success 'fixup that empties commit fails' '
171 test_when_finished "git rebase --abort" &&
174 test_must_fail env FAKE_LINES="1 fixup 2" git rebase -i \
175 goodbye^ reverted-goodbye
179 test_expect_success 'squash that empties commit fails' '
180 test_when_finished "git rebase --abort" &&
183 test_must_fail env FAKE_LINES="1 squash 2" git rebase -i \
184 goodbye^ reverted-goodbye
188 # Must be the last test in this file
189 test_expect_success '$EDITOR and friends are unchanged' '
190 test_editor_unchanged