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 &&
22 test_hook --setup post-rewrite <<-EOF
23 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
24 cat > "$TRASH_DIRECTORY"/post-rewrite.data
29 rm -f post-rewrite.args post-rewrite.data
32 verify_hook_input
() {
33 test_cmp expected.args
"$TRASH_DIRECTORY"/post-rewrite.args
&&
34 test_cmp expected.data
"$TRASH_DIRECTORY"/post-rewrite.data
37 test_expect_success
'git commit --amend' '
39 echo "D new message" > newmsg &&
40 oldsha=$(git rev-parse HEAD^0) &&
41 git commit -Fnewmsg --amend &&
42 echo amend > expected.args &&
43 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
47 test_expect_success
'git commit --amend --no-post-rewrite' '
49 echo "D new message again" > newmsg &&
50 git commit --no-post-rewrite -Fnewmsg --amend &&
51 test ! -f post-rewrite.args &&
52 test ! -f post-rewrite.data
55 test_expect_success
'git rebase --apply' '
58 test_must_fail git rebase --apply --onto A B &&
61 git rebase --continue &&
62 echo rebase >expected.args &&
63 cat >expected.data <<-EOF &&
64 $(git rev-parse C) $(git rev-parse HEAD^)
65 $(git rev-parse D) $(git rev-parse HEAD)
70 test_expect_success
'git rebase --apply --skip' '
73 test_must_fail git rebase --apply --onto A B &&
74 test_must_fail git rebase --skip &&
77 git rebase --continue &&
78 echo rebase >expected.args &&
79 cat >expected.data <<-EOF &&
80 $(git rev-parse C) $(git rev-parse HEAD^)
81 $(git rev-parse D) $(git rev-parse HEAD)
86 test_expect_success
'git rebase --apply --skip the last one' '
89 test_must_fail git rebase --apply --onto D A &&
91 echo rebase >expected.args &&
92 cat >expected.data <<-EOF &&
93 $(git rev-parse E) $(git rev-parse HEAD)
94 $(git rev-parse F) $(git rev-parse HEAD)
99 test_expect_success
'git rebase -m' '
100 git reset --hard D &&
102 test_must_fail git rebase -m --onto A B &&
105 git rebase --continue &&
106 echo rebase >expected.args &&
107 cat >expected.data <<-EOF &&
108 $(git rev-parse C) $(git rev-parse HEAD^)
109 $(git rev-parse D) $(git rev-parse HEAD)
114 test_expect_success
'git rebase -m --skip' '
115 git reset --hard D &&
117 test_must_fail git rebase -m --onto A B &&
118 test_must_fail git rebase --skip &&
121 git rebase --continue &&
122 echo rebase >expected.args &&
123 cat >expected.data <<-EOF &&
124 $(git rev-parse C) $(git rev-parse HEAD^)
125 $(git rev-parse D) $(git rev-parse HEAD)
130 test_expect_success
'git rebase with implicit use of merge backend' '
131 git reset --hard D &&
133 test_must_fail git rebase --keep-empty --onto A B &&
136 git rebase --continue &&
137 echo rebase >expected.args &&
138 cat >expected.data <<-EOF &&
139 $(git rev-parse C) $(git rev-parse HEAD^)
140 $(git rev-parse D) $(git rev-parse HEAD)
145 test_expect_success
'git rebase --skip with implicit use of merge backend' '
146 git reset --hard D &&
148 test_must_fail git rebase --keep-empty --onto A B &&
149 test_must_fail git rebase --skip &&
152 git rebase --continue &&
153 echo rebase >expected.args &&
154 cat >expected.data <<-EOF &&
155 $(git rev-parse C) $(git rev-parse HEAD^)
156 $(git rev-parse D) $(git rev-parse HEAD)
161 .
"$TEST_DIRECTORY"/lib-rebase.sh
165 # Helper to work around the lack of one-shot exporting for
166 # test_must_fail (as it is a shell function)
167 test_fail_interactive_rebase
() {
172 test_must_fail git rebase
-i "$@"
176 test_expect_success
'git rebase -i (unchanged)' '
177 git reset --hard D &&
179 test_fail_interactive_rebase "1 2" --onto A B &&
182 git rebase --continue &&
183 echo rebase >expected.args &&
184 cat >expected.data <<-EOF &&
185 $(git rev-parse C) $(git rev-parse HEAD^)
186 $(git rev-parse D) $(git rev-parse HEAD)
191 test_expect_success
'git rebase -i (skip)' '
192 git reset --hard D &&
194 test_fail_interactive_rebase "2" --onto A B &&
197 git rebase --continue &&
198 echo rebase >expected.args &&
199 cat >expected.data <<-EOF &&
200 $(git rev-parse D) $(git rev-parse HEAD)
205 test_expect_success
'git rebase -i (squash)' '
206 git reset --hard D &&
208 test_fail_interactive_rebase "1 squash 2" --onto A B &&
211 git rebase --continue &&
212 echo rebase >expected.args &&
213 cat >expected.data <<-EOF &&
214 $(git rev-parse C) $(git rev-parse HEAD)
215 $(git rev-parse D) $(git rev-parse HEAD)
220 test_expect_success
'git rebase -i (fixup without conflict)' '
221 git reset --hard D &&
223 FAKE_LINES="1 fixup 2" git rebase -i B &&
224 echo rebase >expected.args &&
225 cat >expected.data <<-EOF &&
226 $(git rev-parse C) $(git rev-parse HEAD)
227 $(git rev-parse D) $(git rev-parse HEAD)
232 test_expect_success
'git rebase -i (double edit)' '
233 git reset --hard D &&
235 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
236 git rebase --continue &&
237 echo something > foo &&
239 git rebase --continue &&
240 echo rebase >expected.args &&
241 cat >expected.data <<-EOF &&
242 $(git rev-parse C) $(git rev-parse HEAD^)
243 $(git rev-parse D) $(git rev-parse HEAD)
248 test_expect_success
'git rebase -i (exec)' '
249 git reset --hard D &&
251 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
252 echo something >bar &&
254 # Fails because of exec false
255 test_must_fail git rebase --continue &&
256 git rebase --continue &&
257 echo rebase >expected.args &&
258 cat >expected.data <<-EOF &&
259 $(git rev-parse C) $(git rev-parse HEAD^)
260 $(git rev-parse D) $(git rev-parse HEAD)