]>
Commit | Line | Data |
---|---|---|
6f6bee3b TR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Thomas Rast | |
4 | # | |
5 | ||
6 | test_description='Test the post-rewrite hook.' | |
966b4be2 | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
9 | ||
6f6bee3b TR |
10 | . ./test-lib.sh |
11 | ||
12 | test_expect_success 'setup' ' | |
13 | test_commit A foo A && | |
14 | test_commit B foo B && | |
15 | test_commit C foo C && | |
ef88ad23 JH |
16 | test_commit D foo D && |
17 | git checkout A^0 && | |
18 | test_commit E bar E && | |
19 | test_commit F foo F && | |
e032abd5 PW |
20 | git checkout B && |
21 | git merge E && | |
22 | git tag merge-E && | |
23 | test_commit G G && | |
24 | test_commit H H && | |
25 | test_commit I I && | |
c36c6285 | 26 | git checkout main && |
6f6bee3b | 27 | |
c36c6285 ÆAB |
28 | test_hook --setup post-rewrite <<-EOF |
29 | echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args | |
30 | cat > "$TRASH_DIRECTORY"/post-rewrite.data | |
31 | EOF | |
32 | ' | |
6f6bee3b TR |
33 | |
34 | clear_hook_input () { | |
35 | rm -f post-rewrite.args post-rewrite.data | |
36 | } | |
37 | ||
38 | verify_hook_input () { | |
1fee89ce FC |
39 | test_cmp expected.args "$TRASH_DIRECTORY"/post-rewrite.args && |
40 | test_cmp expected.data "$TRASH_DIRECTORY"/post-rewrite.data | |
6f6bee3b TR |
41 | } |
42 | ||
43 | test_expect_success 'git commit --amend' ' | |
44 | clear_hook_input && | |
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 && | |
50 | verify_hook_input | |
51 | ' | |
52 | ||
53 | test_expect_success 'git commit --amend --no-post-rewrite' ' | |
54 | clear_hook_input && | |
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 | |
59 | ' | |
60 | ||
10cdb9f3 | 61 | test_expect_success 'git rebase --apply' ' |
96e19488 TR |
62 | git reset --hard D && |
63 | clear_hook_input && | |
10cdb9f3 | 64 | test_must_fail git rebase --apply --onto A B && |
96e19488 TR |
65 | echo C > foo && |
66 | git add foo && | |
67 | git rebase --continue && | |
68 | echo rebase >expected.args && | |
141ff8f9 JH |
69 | cat >expected.data <<-EOF && |
70 | $(git rev-parse C) $(git rev-parse HEAD^) | |
71 | $(git rev-parse D) $(git rev-parse HEAD) | |
72 | EOF | |
96e19488 TR |
73 | verify_hook_input |
74 | ' | |
75 | ||
10cdb9f3 | 76 | test_expect_success 'git rebase --apply --skip' ' |
96e19488 TR |
77 | git reset --hard D && |
78 | clear_hook_input && | |
10cdb9f3 | 79 | test_must_fail git rebase --apply --onto A B && |
96e19488 TR |
80 | test_must_fail git rebase --skip && |
81 | echo D > foo && | |
82 | git add foo && | |
83 | git rebase --continue && | |
84 | echo rebase >expected.args && | |
141ff8f9 | 85 | cat >expected.data <<-EOF && |
45339f74 | 86 | $(git rev-parse C) $(git rev-parse HEAD^) |
141ff8f9 JH |
87 | $(git rev-parse D) $(git rev-parse HEAD) |
88 | EOF | |
96e19488 TR |
89 | verify_hook_input |
90 | ' | |
91 | ||
10cdb9f3 | 92 | test_expect_success 'git rebase --apply --skip the last one' ' |
ef88ad23 JH |
93 | git reset --hard F && |
94 | clear_hook_input && | |
10cdb9f3 | 95 | test_must_fail git rebase --apply --onto D A && |
ef88ad23 JH |
96 | git rebase --skip && |
97 | echo rebase >expected.args && | |
141ff8f9 JH |
98 | cat >expected.data <<-EOF && |
99 | $(git rev-parse E) $(git rev-parse HEAD) | |
45339f74 | 100 | $(git rev-parse F) $(git rev-parse HEAD) |
141ff8f9 | 101 | EOF |
ef88ad23 JH |
102 | verify_hook_input |
103 | ' | |
104 | ||
b079feed TR |
105 | test_expect_success 'git rebase -m' ' |
106 | git reset --hard D && | |
107 | clear_hook_input && | |
108 | test_must_fail git rebase -m --onto A B && | |
109 | echo C > foo && | |
110 | git add foo && | |
111 | git rebase --continue && | |
112 | echo rebase >expected.args && | |
141ff8f9 JH |
113 | cat >expected.data <<-EOF && |
114 | $(git rev-parse C) $(git rev-parse HEAD^) | |
115 | $(git rev-parse D) $(git rev-parse HEAD) | |
116 | EOF | |
b079feed TR |
117 | verify_hook_input |
118 | ' | |
119 | ||
120 | test_expect_success 'git rebase -m --skip' ' | |
121 | git reset --hard D && | |
122 | clear_hook_input && | |
e951e8f6 | 123 | test_must_fail git rebase -m --onto A B && |
b079feed TR |
124 | test_must_fail git rebase --skip && |
125 | echo D > foo && | |
126 | git add foo && | |
127 | git rebase --continue && | |
128 | echo rebase >expected.args && | |
141ff8f9 | 129 | cat >expected.data <<-EOF && |
45339f74 | 130 | $(git rev-parse C) $(git rev-parse HEAD^) |
141ff8f9 JH |
131 | $(git rev-parse D) $(git rev-parse HEAD) |
132 | EOF | |
b079feed TR |
133 | verify_hook_input |
134 | ' | |
135 | ||
10cdb9f3 | 136 | test_expect_success 'git rebase with implicit use of merge backend' ' |
54006779 EN |
137 | git reset --hard D && |
138 | clear_hook_input && | |
dd605e49 | 139 | test_must_fail git rebase --keep-empty --onto A B && |
54006779 EN |
140 | echo C > foo && |
141 | git add foo && | |
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) | |
147 | EOF | |
148 | verify_hook_input | |
149 | ' | |
150 | ||
10cdb9f3 | 151 | test_expect_success 'git rebase --skip with implicit use of merge backend' ' |
54006779 EN |
152 | git reset --hard D && |
153 | clear_hook_input && | |
dd605e49 | 154 | test_must_fail git rebase --keep-empty --onto A B && |
54006779 EN |
155 | test_must_fail git rebase --skip && |
156 | echo D > foo && | |
157 | git add foo && | |
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) | |
163 | EOF | |
164 | verify_hook_input | |
165 | ' | |
166 | ||
b079feed TR |
167 | . "$TEST_DIRECTORY"/lib-rebase.sh |
168 | ||
169 | set_fake_editor | |
170 | ||
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 () { | |
174 | ( | |
175 | FAKE_LINES="$1" && | |
176 | shift && | |
177 | export FAKE_LINES && | |
178 | test_must_fail git rebase -i "$@" | |
179 | ) | |
180 | } | |
181 | ||
e032abd5 PW |
182 | test_expect_success 'git rebase with failed pick' ' |
183 | clear_hook_input && | |
184 | cat >todo <<-\EOF && | |
185 | exec >bar | |
186 | merge -C merge-E E | |
187 | exec >G | |
188 | pick G | |
189 | exec >H 2>I | |
190 | pick H | |
191 | fixup I | |
192 | EOF | |
193 | ||
194 | ( | |
195 | set_replace_editor todo && | |
196 | test_must_fail git rebase -i D D 2>err | |
197 | ) && | |
198 | grep "would be overwritten" err && | |
199 | rm bar && | |
200 | ||
201 | test_must_fail git rebase --continue 2>err && | |
202 | grep "would be overwritten" err && | |
203 | rm G && | |
204 | ||
205 | test_must_fail git rebase --continue 2>err && | |
206 | grep "would be overwritten" err && | |
207 | rm H && | |
208 | ||
209 | test_must_fail git rebase --continue 2>err && | |
210 | grep "would be overwritten" err && | |
211 | rm I && | |
212 | ||
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) | |
220 | EOF | |
221 | verify_hook_input | |
222 | ' | |
223 | ||
b079feed TR |
224 | test_expect_success 'git rebase -i (unchanged)' ' |
225 | git reset --hard D && | |
226 | clear_hook_input && | |
227 | test_fail_interactive_rebase "1 2" --onto A B && | |
228 | echo C > foo && | |
229 | git add foo && | |
230 | git rebase --continue && | |
231 | echo rebase >expected.args && | |
141ff8f9 JH |
232 | cat >expected.data <<-EOF && |
233 | $(git rev-parse C) $(git rev-parse HEAD^) | |
234 | $(git rev-parse D) $(git rev-parse HEAD) | |
235 | EOF | |
b079feed TR |
236 | verify_hook_input |
237 | ' | |
238 | ||
239 | test_expect_success 'git rebase -i (skip)' ' | |
240 | git reset --hard D && | |
241 | clear_hook_input && | |
242 | test_fail_interactive_rebase "2" --onto A B && | |
243 | echo D > foo && | |
244 | git add foo && | |
245 | git rebase --continue && | |
246 | echo rebase >expected.args && | |
141ff8f9 JH |
247 | cat >expected.data <<-EOF && |
248 | $(git rev-parse D) $(git rev-parse HEAD) | |
249 | EOF | |
b079feed TR |
250 | verify_hook_input |
251 | ' | |
252 | ||
253 | test_expect_success 'git rebase -i (squash)' ' | |
254 | git reset --hard D && | |
255 | clear_hook_input && | |
256 | test_fail_interactive_rebase "1 squash 2" --onto A B && | |
257 | echo C > foo && | |
258 | git add foo && | |
259 | git rebase --continue && | |
260 | echo rebase >expected.args && | |
141ff8f9 JH |
261 | cat >expected.data <<-EOF && |
262 | $(git rev-parse C) $(git rev-parse HEAD) | |
263 | $(git rev-parse D) $(git rev-parse HEAD) | |
264 | EOF | |
b079feed TR |
265 | verify_hook_input |
266 | ' | |
267 | ||
268 | test_expect_success 'git rebase -i (fixup without conflict)' ' | |
269 | git reset --hard D && | |
270 | clear_hook_input && | |
271 | FAKE_LINES="1 fixup 2" git rebase -i B && | |
272 | echo rebase >expected.args && | |
141ff8f9 JH |
273 | cat >expected.data <<-EOF && |
274 | $(git rev-parse C) $(git rev-parse HEAD) | |
275 | $(git rev-parse D) $(git rev-parse HEAD) | |
276 | EOF | |
b079feed TR |
277 | verify_hook_input |
278 | ' | |
279 | ||
0acb62f2 TR |
280 | test_expect_success 'git rebase -i (double edit)' ' |
281 | git reset --hard D && | |
282 | clear_hook_input && | |
283 | FAKE_LINES="edit 1 edit 2" git rebase -i B && | |
284 | git rebase --continue && | |
285 | echo something > foo && | |
286 | git add foo && | |
287 | git rebase --continue && | |
288 | echo rebase >expected.args && | |
141ff8f9 JH |
289 | cat >expected.data <<-EOF && |
290 | $(git rev-parse C) $(git rev-parse HEAD^) | |
291 | $(git rev-parse D) $(git rev-parse HEAD) | |
292 | EOF | |
0acb62f2 TR |
293 | verify_hook_input |
294 | ' | |
295 | ||
b12d3e90 | 296 | test_expect_success 'git rebase -i (exec)' ' |
1d968ca6 MM |
297 | git reset --hard D && |
298 | clear_hook_input && | |
299 | FAKE_LINES="edit 1 exec_false 2" git rebase -i B && | |
300 | echo something >bar && | |
301 | git add bar && | |
302 | # Fails because of exec false | |
303 | test_must_fail git rebase --continue && | |
304 | git rebase --continue && | |
305 | echo rebase >expected.args && | |
141ff8f9 JH |
306 | cat >expected.data <<-EOF && |
307 | $(git rev-parse C) $(git rev-parse HEAD^) | |
308 | $(git rev-parse D) $(git rev-parse HEAD) | |
309 | EOF | |
1d968ca6 MM |
310 | verify_hook_input |
311 | ' | |
312 | ||
6f6bee3b | 313 | test_done |