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
10 TEST_PASSES_SANITIZE_LEAK
=true
13 test_expect_success
'setup' '
14 test_commit A foo A &&
15 test_commit B foo B &&
16 test_commit C foo C &&
17 test_commit D foo D &&
19 test_commit E bar E &&
20 test_commit F foo F &&
29 test_hook --setup post-rewrite <<-EOF
30 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
31 cat > "$TRASH_DIRECTORY"/post-rewrite.data
36 rm -f post-rewrite.args post-rewrite.data
39 verify_hook_input
() {
40 test_cmp expected.args
"$TRASH_DIRECTORY"/post-rewrite.args
&&
41 test_cmp expected.data
"$TRASH_DIRECTORY"/post-rewrite.data
44 test_expect_success
'git commit --amend' '
46 echo "D new message" > newmsg &&
47 oldsha=$(git rev-parse HEAD^0) &&
48 git commit -Fnewmsg --amend &&
49 echo amend > expected.args &&
50 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
54 test_expect_success
'git commit --amend --no-post-rewrite' '
56 echo "D new message again" > newmsg &&
57 git commit --no-post-rewrite -Fnewmsg --amend &&
58 test ! -f post-rewrite.args &&
59 test ! -f post-rewrite.data
62 test_expect_success
'git rebase --apply' '
65 test_must_fail git rebase --apply --onto A B &&
68 git rebase --continue &&
69 echo rebase >expected.args &&
70 cat >expected.data <<-EOF &&
71 $(git rev-parse C) $(git rev-parse HEAD^)
72 $(git rev-parse D) $(git rev-parse HEAD)
77 test_expect_success
'git rebase --apply --skip' '
80 test_must_fail git rebase --apply --onto A B &&
81 test_must_fail git rebase --skip &&
84 git rebase --continue &&
85 echo rebase >expected.args &&
86 cat >expected.data <<-EOF &&
87 $(git rev-parse C) $(git rev-parse HEAD^)
88 $(git rev-parse D) $(git rev-parse HEAD)
93 test_expect_success
'git rebase --apply --skip the last one' '
96 test_must_fail git rebase --apply --onto D A &&
98 echo rebase >expected.args &&
99 cat >expected.data <<-EOF &&
100 $(git rev-parse E) $(git rev-parse HEAD)
101 $(git rev-parse F) $(git rev-parse HEAD)
106 test_expect_success
'git rebase -m' '
107 git reset --hard D &&
109 test_must_fail git rebase -m --onto A B &&
112 git rebase --continue &&
113 echo rebase >expected.args &&
114 cat >expected.data <<-EOF &&
115 $(git rev-parse C) $(git rev-parse HEAD^)
116 $(git rev-parse D) $(git rev-parse HEAD)
121 test_expect_success
'git rebase -m --skip' '
122 git reset --hard D &&
124 test_must_fail git rebase -m --onto A B &&
125 test_must_fail git rebase --skip &&
128 git rebase --continue &&
129 echo rebase >expected.args &&
130 cat >expected.data <<-EOF &&
131 $(git rev-parse C) $(git rev-parse HEAD^)
132 $(git rev-parse D) $(git rev-parse HEAD)
137 test_expect_success
'git rebase with implicit use of merge backend' '
138 git reset --hard D &&
140 test_must_fail git rebase --keep-empty --onto A B &&
143 git rebase --continue &&
144 echo rebase >expected.args &&
145 cat >expected.data <<-EOF &&
146 $(git rev-parse C) $(git rev-parse HEAD^)
147 $(git rev-parse D) $(git rev-parse HEAD)
152 test_expect_success
'git rebase --skip with implicit use of merge backend' '
153 git reset --hard D &&
155 test_must_fail git rebase --keep-empty --onto A B &&
156 test_must_fail git rebase --skip &&
159 git rebase --continue &&
160 echo rebase >expected.args &&
161 cat >expected.data <<-EOF &&
162 $(git rev-parse C) $(git rev-parse HEAD^)
163 $(git rev-parse D) $(git rev-parse HEAD)
168 .
"$TEST_DIRECTORY"/lib-rebase.sh
172 # Helper to work around the lack of one-shot exporting for
173 # test_must_fail (as it is a shell function)
174 test_fail_interactive_rebase
() {
179 test_must_fail git rebase
-i "$@"
183 test_expect_success
'git rebase with failed pick' '
196 set_replace_editor todo &&
197 test_must_fail git rebase -i D D 2>err
199 grep "would be overwritten" err &&
202 test_must_fail git rebase --continue 2>err &&
203 grep "would be overwritten" err &&
206 test_must_fail git rebase --continue 2>err &&
207 grep "would be overwritten" err &&
210 test_must_fail git rebase --continue 2>err &&
211 grep "would be overwritten" err &&
214 git rebase --continue &&
215 echo rebase >expected.args &&
216 cat >expected.data <<-EOF &&
217 $(git rev-parse merge-E) $(git rev-parse HEAD~2)
218 $(git rev-parse G) $(git rev-parse HEAD~1)
219 $(git rev-parse H) $(git rev-parse HEAD)
220 $(git rev-parse I) $(git rev-parse HEAD)
225 test_expect_success
'git rebase -i (unchanged)' '
226 git reset --hard D &&
228 test_fail_interactive_rebase "1 2" --onto A B &&
231 git rebase --continue &&
232 echo rebase >expected.args &&
233 cat >expected.data <<-EOF &&
234 $(git rev-parse C) $(git rev-parse HEAD^)
235 $(git rev-parse D) $(git rev-parse HEAD)
240 test_expect_success
'git rebase -i (skip)' '
241 git reset --hard D &&
243 test_fail_interactive_rebase "2" --onto A B &&
246 git rebase --continue &&
247 echo rebase >expected.args &&
248 cat >expected.data <<-EOF &&
249 $(git rev-parse D) $(git rev-parse HEAD)
254 test_expect_success
'git rebase -i (squash)' '
255 git reset --hard D &&
257 test_fail_interactive_rebase "1 squash 2" --onto A B &&
260 git rebase --continue &&
261 echo rebase >expected.args &&
262 cat >expected.data <<-EOF &&
263 $(git rev-parse C) $(git rev-parse HEAD)
264 $(git rev-parse D) $(git rev-parse HEAD)
269 test_expect_success
'git rebase -i (fixup without conflict)' '
270 git reset --hard D &&
272 FAKE_LINES="1 fixup 2" git rebase -i B &&
273 echo rebase >expected.args &&
274 cat >expected.data <<-EOF &&
275 $(git rev-parse C) $(git rev-parse HEAD)
276 $(git rev-parse D) $(git rev-parse HEAD)
281 test_expect_success
'git rebase -i (double edit)' '
282 git reset --hard D &&
284 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
285 git rebase --continue &&
286 echo something > foo &&
288 git rebase --continue &&
289 echo rebase >expected.args &&
290 cat >expected.data <<-EOF &&
291 $(git rev-parse C) $(git rev-parse HEAD^)
292 $(git rev-parse D) $(git rev-parse HEAD)
297 test_expect_success
'git rebase -i (exec)' '
298 git reset --hard D &&
300 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
301 echo something >bar &&
303 # Fails because of exec false
304 test_must_fail git rebase --continue &&
305 git rebase --continue &&
306 echo rebase >expected.args &&
307 cat >expected.data <<-EOF &&
308 $(git rev-parse C) $(git rev-parse HEAD^)
309 $(git rev-parse D) $(git rev-parse HEAD)