3 # Copyright (c) 2010 Thomas Rast
6 test_description
='Test the post-rewrite hook.'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 test_expect_success
'setup' '
13 test_commit A foo A &&
14 test_commit B foo B &&
15 test_commit C foo C &&
16 test_commit D foo D &&
18 test_commit E bar E &&
19 test_commit F foo F &&
28 test_hook --setup post-rewrite <<-EOF
29 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
30 cat > "$TRASH_DIRECTORY"/post-rewrite.data
35 rm -f post-rewrite.args post-rewrite.data
38 verify_hook_input
() {
39 test_cmp expected.args
"$TRASH_DIRECTORY"/post-rewrite.args
&&
40 test_cmp expected.data
"$TRASH_DIRECTORY"/post-rewrite.data
43 test_expect_success
'git commit --amend' '
45 echo "D new message" > newmsg &&
46 oldsha=$(git rev-parse HEAD^0) &&
47 git commit -Fnewmsg --amend &&
48 echo amend > expected.args &&
49 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
53 test_expect_success
'git commit --amend --no-post-rewrite' '
55 echo "D new message again" > newmsg &&
56 git commit --no-post-rewrite -Fnewmsg --amend &&
57 test ! -f post-rewrite.args &&
58 test ! -f post-rewrite.data
61 test_expect_success
'git rebase --apply' '
64 test_must_fail git rebase --apply --onto A B &&
67 git rebase --continue &&
68 echo rebase >expected.args &&
69 cat >expected.data <<-EOF &&
70 $(git rev-parse C) $(git rev-parse HEAD^)
71 $(git rev-parse D) $(git rev-parse HEAD)
76 test_expect_success
'git rebase --apply --skip' '
79 test_must_fail git rebase --apply --onto A B &&
80 test_must_fail git rebase --skip &&
83 git rebase --continue &&
84 echo rebase >expected.args &&
85 cat >expected.data <<-EOF &&
86 $(git rev-parse C) $(git rev-parse HEAD^)
87 $(git rev-parse D) $(git rev-parse HEAD)
92 test_expect_success
'git rebase --apply --skip the last one' '
95 test_must_fail git rebase --apply --onto D A &&
97 echo rebase >expected.args &&
98 cat >expected.data <<-EOF &&
99 $(git rev-parse E) $(git rev-parse HEAD)
100 $(git rev-parse F) $(git rev-parse HEAD)
105 test_expect_success
'git rebase -m' '
106 git reset --hard D &&
108 test_must_fail git rebase -m --onto A B &&
111 git rebase --continue &&
112 echo rebase >expected.args &&
113 cat >expected.data <<-EOF &&
114 $(git rev-parse C) $(git rev-parse HEAD^)
115 $(git rev-parse D) $(git rev-parse HEAD)
120 test_expect_success
'git rebase -m --skip' '
121 git reset --hard D &&
123 test_must_fail git rebase -m --onto A B &&
124 test_must_fail git rebase --skip &&
127 git rebase --continue &&
128 echo rebase >expected.args &&
129 cat >expected.data <<-EOF &&
130 $(git rev-parse C) $(git rev-parse HEAD^)
131 $(git rev-parse D) $(git rev-parse HEAD)
136 test_expect_success
'git rebase with implicit use of merge backend' '
137 git reset --hard D &&
139 test_must_fail git rebase --keep-empty --onto A B &&
142 git rebase --continue &&
143 echo rebase >expected.args &&
144 cat >expected.data <<-EOF &&
145 $(git rev-parse C) $(git rev-parse HEAD^)
146 $(git rev-parse D) $(git rev-parse HEAD)
151 test_expect_success
'git rebase --skip with implicit use of merge backend' '
152 git reset --hard D &&
154 test_must_fail git rebase --keep-empty --onto A B &&
155 test_must_fail git rebase --skip &&
158 git rebase --continue &&
159 echo rebase >expected.args &&
160 cat >expected.data <<-EOF &&
161 $(git rev-parse C) $(git rev-parse HEAD^)
162 $(git rev-parse D) $(git rev-parse HEAD)
167 .
"$TEST_DIRECTORY"/lib-rebase.sh
171 # Helper to work around the lack of one-shot exporting for
172 # test_must_fail (as it is a shell function)
173 test_fail_interactive_rebase
() {
178 test_must_fail git rebase
-i "$@"
182 test_expect_success
'git rebase with failed pick' '
195 set_replace_editor todo &&
196 test_must_fail git rebase -i D D 2>err
198 grep "would be overwritten" err &&
201 test_must_fail git rebase --continue 2>err &&
202 grep "would be overwritten" err &&
205 test_must_fail git rebase --continue 2>err &&
206 grep "would be overwritten" err &&
209 test_must_fail git rebase --continue 2>err &&
210 grep "would be overwritten" err &&
213 git rebase --continue &&
214 echo rebase >expected.args &&
215 cat >expected.data <<-EOF &&
216 $(git rev-parse merge-E) $(git rev-parse HEAD~2)
217 $(git rev-parse G) $(git rev-parse HEAD~1)
218 $(git rev-parse H) $(git rev-parse HEAD)
219 $(git rev-parse I) $(git rev-parse HEAD)
224 test_expect_success
'git rebase -i (unchanged)' '
225 git reset --hard D &&
227 test_fail_interactive_rebase "1 2" --onto A B &&
230 git rebase --continue &&
231 echo rebase >expected.args &&
232 cat >expected.data <<-EOF &&
233 $(git rev-parse C) $(git rev-parse HEAD^)
234 $(git rev-parse D) $(git rev-parse HEAD)
239 test_expect_success
'git rebase -i (skip)' '
240 git reset --hard D &&
242 test_fail_interactive_rebase "2" --onto A B &&
245 git rebase --continue &&
246 echo rebase >expected.args &&
247 cat >expected.data <<-EOF &&
248 $(git rev-parse D) $(git rev-parse HEAD)
253 test_expect_success
'git rebase -i (squash)' '
254 git reset --hard D &&
256 test_fail_interactive_rebase "1 squash 2" --onto A B &&
259 git rebase --continue &&
260 echo rebase >expected.args &&
261 cat >expected.data <<-EOF &&
262 $(git rev-parse C) $(git rev-parse HEAD)
263 $(git rev-parse D) $(git rev-parse HEAD)
268 test_expect_success
'git rebase -i (fixup without conflict)' '
269 git reset --hard D &&
271 FAKE_LINES="1 fixup 2" git rebase -i B &&
272 echo rebase >expected.args &&
273 cat >expected.data <<-EOF &&
274 $(git rev-parse C) $(git rev-parse HEAD)
275 $(git rev-parse D) $(git rev-parse HEAD)
280 test_expect_success
'git rebase -i (double edit)' '
281 git reset --hard D &&
283 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
284 git rebase --continue &&
285 echo something > foo &&
287 git rebase --continue &&
288 echo rebase >expected.args &&
289 cat >expected.data <<-EOF &&
290 $(git rev-parse C) $(git rev-parse HEAD^)
291 $(git rev-parse D) $(git rev-parse HEAD)
296 test_expect_success
'git rebase -i (exec)' '
297 git reset --hard D &&
299 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
300 echo something >bar &&
302 # Fails because of exec false
303 test_must_fail git rebase --continue &&
304 git rebase --continue &&
305 echo rebase >expected.args &&
306 cat >expected.data <<-EOF &&
307 $(git rev-parse C) $(git rev-parse HEAD^)
308 $(git rev-parse D) $(git rev-parse HEAD)