]>
Commit | Line | Data |
---|---|---|
a17c4101 CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Christian Couder | |
4 | # | |
3604e7c5 | 5 | test_description='Tests git bisect functionality' |
a17c4101 | 6 | |
0a5280a9 JH |
7 | exec </dev/null |
8 | ||
1550bb6e | 9 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
10 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
11 | ||
a17c4101 CC |
12 | . ./test-lib.sh |
13 | ||
14 | add_line_into_file() | |
15 | { | |
16 | _line=$1 | |
17 | _file=$2 | |
18 | ||
19 | if [ -f "$_file" ]; then | |
20 | echo "$_line" >> $_file || return $? | |
21 | MSG="Add <$_line> into <$_file>." | |
22 | else | |
23 | echo "$_line" > $_file || return $? | |
24 | git add $_file || return $? | |
25 | MSG="Create file <$_file> with <$_line> inside." | |
26 | fi | |
27 | ||
ab69e89c | 28 | test_tick |
3604e7c5 | 29 | git commit --quiet -m "$MSG" $_file |
a17c4101 CC |
30 | } |
31 | ||
32 | HASH1= | |
ab69e89c | 33 | HASH2= |
a17c4101 CC |
34 | HASH3= |
35 | HASH4= | |
36 | ||
929bf9db ÆAB |
37 | test_bisect_usage () { |
38 | local code="$1" && | |
39 | shift && | |
40 | cat >expect && | |
41 | test_expect_code $code "$@" >out 2>actual && | |
42 | test_must_be_empty out && | |
43 | test_cmp expect actual | |
44 | } | |
45 | ||
46 | test_expect_success 'bisect usage' " | |
47 | test_bisect_usage 1 git bisect reset extra1 extra2 <<-\EOF && | |
48 | error: 'git bisect reset' requires either no argument or a commit | |
49 | EOF | |
50 | test_bisect_usage 1 git bisect terms extra1 extra2 <<-\EOF && | |
51 | error: 'git bisect terms' requires 0 or 1 argument | |
52 | EOF | |
53 | test_bisect_usage 1 git bisect next extra1 <<-\EOF && | |
54 | error: 'git bisect next' requires 0 arguments | |
55 | EOF | |
56 | test_bisect_usage 1 git bisect log extra1 <<-\EOF && | |
57 | error: We are not bisecting. | |
58 | EOF | |
59 | test_bisect_usage 1 git bisect replay <<-\EOF && | |
60 | error: no logfile given | |
61 | EOF | |
62 | test_bisect_usage 1 git bisect run <<-\EOF | |
63 | error: 'git bisect run' failed: no command provided. | |
64 | EOF | |
65 | " | |
66 | ||
ab69e89c JH |
67 | test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' ' |
68 | add_line_into_file "1: Hello World" hello && | |
69 | HASH1=$(git rev-parse --verify HEAD) && | |
a17c4101 | 70 | add_line_into_file "2: A new day for git" hello && |
ab69e89c | 71 | HASH2=$(git rev-parse --verify HEAD) && |
a17c4101 | 72 | add_line_into_file "3: Another new day for git" hello && |
ab69e89c | 73 | HASH3=$(git rev-parse --verify HEAD) && |
a17c4101 | 74 | add_line_into_file "4: Ciao for now" hello && |
ab69e89c JH |
75 | HASH4=$(git rev-parse --verify HEAD) |
76 | ' | |
a17c4101 | 77 | |
0a5280a9 | 78 | test_expect_success 'bisect starts with only one bad' ' |
4f506716 JH |
79 | git bisect reset && |
80 | git bisect start && | |
0a5280a9 JH |
81 | git bisect bad $HASH4 && |
82 | git bisect next | |
4f506716 JH |
83 | ' |
84 | ||
f9487929 | 85 | test_expect_success 'bisect does not start with only one good' ' |
4f506716 JH |
86 | git bisect reset && |
87 | git bisect start && | |
e4e6e8b4 JK |
88 | git bisect good $HASH1 && |
89 | test_must_fail git bisect next | |
4f506716 JH |
90 | ' |
91 | ||
92 | test_expect_success 'bisect start with one bad and good' ' | |
93 | git bisect reset && | |
94 | git bisect start && | |
95 | git bisect good $HASH1 && | |
96 | git bisect bad $HASH4 && | |
97 | git bisect next | |
98 | ' | |
99 | ||
d3e54c88 | 100 | test_expect_success 'bisect fails if given any junk instead of revs' ' |
e3389075 | 101 | git bisect reset && |
d3e54c88 CC |
102 | test_must_fail git bisect start foo $HASH1 -- && |
103 | test_must_fail git bisect start $HASH4 $HASH1 bar -- && | |
104 | test -z "$(git for-each-ref "refs/bisect/*")" && | |
b890fa33 | 105 | test -z "$(ls .git/BISECT_* 2>/dev/null)" && |
e3389075 CC |
106 | git bisect start && |
107 | test_must_fail git bisect good foo $HASH1 && | |
108 | test_must_fail git bisect good $HASH1 bar && | |
109 | test_must_fail git bisect bad frotz && | |
110 | test_must_fail git bisect bad $HASH3 $HASH4 && | |
111 | test_must_fail git bisect skip bar $HASH3 && | |
112 | test_must_fail git bisect skip $HASH1 foo && | |
d3e54c88 | 113 | test -z "$(git for-each-ref "refs/bisect/*")" && |
e3389075 CC |
114 | git bisect good $HASH1 && |
115 | git bisect bad $HASH4 | |
4f506716 JH |
116 | ' |
117 | ||
73c6de06 CC |
118 | test_expect_success 'bisect start without -- takes unknown arg as pathspec' ' |
119 | git bisect reset && | |
120 | git bisect start foo bar && | |
121 | grep foo ".git/BISECT_NAMES" && | |
122 | grep bar ".git/BISECT_NAMES" | |
123 | ' | |
124 | ||
7fb89047 RJ |
125 | test_expect_success 'bisect reset: back in a branch checked out also elsewhere' ' |
126 | echo "shared" > branch.expect && | |
127 | test_bisect_reset() { | |
128 | git -C $1 bisect start && | |
129 | git -C $1 bisect good $HASH1 && | |
130 | git -C $1 bisect bad $HASH3 && | |
131 | git -C $1 bisect reset && | |
132 | git -C $1 branch --show-current > branch.output && | |
133 | cmp branch.expect branch.output | |
134 | } && | |
135 | test_when_finished " | |
136 | git worktree remove wt1 && | |
137 | git worktree remove wt2 && | |
138 | git branch -d shared | |
139 | " && | |
140 | git worktree add wt1 -b shared && | |
141 | git worktree add wt2 -f shared && | |
142 | # we test in both worktrees to ensure that works | |
143 | # as expected with "first" and "next" worktrees | |
144 | test_bisect_reset wt1 && | |
145 | test_bisect_reset wt2 | |
146 | ' | |
147 | ||
1550bb6e | 148 | test_expect_success 'bisect reset: back in the main branch' ' |
fce0499f | 149 | git bisect reset && |
1550bb6e | 150 | echo "* main" > branch.expect && |
fce0499f CC |
151 | git branch > branch.output && |
152 | cmp branch.expect branch.output | |
153 | ' | |
154 | ||
155 | test_expect_success 'bisect reset: back in another branch' ' | |
156 | git checkout -b other && | |
157 | git bisect start && | |
158 | git bisect good $HASH1 && | |
159 | git bisect bad $HASH3 && | |
160 | git bisect reset && | |
1550bb6e | 161 | echo " main" > branch.expect && |
fce0499f CC |
162 | echo "* other" >> branch.expect && |
163 | git branch > branch.output && | |
164 | cmp branch.expect branch.output | |
165 | ' | |
166 | ||
167 | test_expect_success 'bisect reset when not bisecting' ' | |
168 | git bisect reset && | |
169 | git branch > branch.output && | |
170 | cmp branch.expect branch.output | |
171 | ' | |
172 | ||
947a604b CC |
173 | test_expect_success 'bisect reset removes packed refs' ' |
174 | git bisect reset && | |
175 | git bisect start && | |
176 | git bisect good $HASH1 && | |
177 | git bisect bad $HASH3 && | |
178 | git pack-refs --all --prune && | |
179 | git bisect next && | |
180 | git bisect reset && | |
181 | test -z "$(git for-each-ref "refs/bisect/*")" && | |
182 | test -z "$(git for-each-ref "refs/heads/bisect")" | |
183 | ' | |
184 | ||
b704a8b3 JS |
185 | test_expect_success 'bisect reset removes bisect state after --no-checkout' ' |
186 | git bisect reset && | |
187 | git bisect start --no-checkout && | |
188 | git bisect good $HASH1 && | |
189 | git bisect bad $HASH3 && | |
190 | git bisect next && | |
191 | git bisect reset && | |
192 | test -z "$(git for-each-ref "refs/bisect/*")" && | |
193 | test -z "$(git for-each-ref "refs/heads/bisect")" && | |
194 | test -z "$(git for-each-ref "BISECT_HEAD")" | |
195 | ' | |
196 | ||
d3aca585 CC |
197 | test_expect_success 'bisect start: back in good branch' ' |
198 | git branch > branch.output && | |
199 | grep "* other" branch.output > /dev/null && | |
200 | git bisect start $HASH4 $HASH1 -- && | |
201 | git bisect good && | |
202 | git bisect start $HASH4 $HASH1 -- && | |
203 | git bisect bad && | |
204 | git bisect reset && | |
205 | git branch > branch.output && | |
206 | grep "* other" branch.output > /dev/null | |
207 | ' | |
208 | ||
4764f464 JS |
209 | test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' ' |
210 | git bisect reset && | |
d3aca585 CC |
211 | test_must_fail git bisect start $HASH4 foo -- && |
212 | git branch > branch.output && | |
213 | grep "* other" branch.output > /dev/null && | |
085ba9b5 | 214 | test_path_is_missing .git/BISECT_START |
d3aca585 CC |
215 | ' |
216 | ||
4764f464 JS |
217 | test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' ' |
218 | git bisect start $HASH4 $HASH1 -- && | |
219 | git bisect good && | |
220 | cp .git/BISECT_START saved && | |
221 | test_must_fail git bisect start $HASH4 foo -- && | |
222 | git branch > branch.output && | |
6789275d | 223 | test_grep "* (no branch, bisect started on other)" branch.output > /dev/null && |
4764f464 JS |
224 | test_cmp saved .git/BISECT_START |
225 | ' | |
ba963de8 | 226 | test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' ' |
d3aca585 CC |
227 | git bisect start $HASH4 $HASH1 -- && |
228 | git bisect good && | |
229 | test_must_fail git bisect start $HASH1 $HASH4 -- && | |
230 | git branch > branch.output && | |
231 | grep "* other" branch.output > /dev/null && | |
085ba9b5 | 232 | test_path_is_missing .git/BISECT_START |
d3aca585 CC |
233 | ' |
234 | ||
ba963de8 | 235 | test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' ' |
d3aca585 CC |
236 | echo "temp stuff" > hello && |
237 | test_must_fail git bisect start $HASH4 $HASH1 -- && | |
238 | git branch && | |
239 | git branch > branch.output && | |
240 | grep "* other" branch.output > /dev/null && | |
085ba9b5 | 241 | test_path_is_missing .git/BISECT_START && |
ba963de8 CC |
242 | test -z "$(git for-each-ref "refs/bisect/*")" && |
243 | git checkout HEAD hello | |
d3aca585 CC |
244 | ' |
245 | ||
97e1c51e CC |
246 | # $HASH1 is good, $HASH4 is bad, we skip $HASH3 |
247 | # but $HASH2 is bad, | |
248 | # so we should find $HASH2 as the first bad commit | |
41ccfdd9 | 249 | test_expect_success 'bisect skip: successful result' ' |
e4e6e8b4 | 250 | test_when_finished git bisect reset && |
97e1c51e CC |
251 | git bisect reset && |
252 | git bisect start $HASH4 $HASH1 && | |
253 | git bisect skip && | |
254 | git bisect bad > my_bisect_log.txt && | |
e4e6e8b4 | 255 | grep "$HASH2 is the first bad commit" my_bisect_log.txt |
97e1c51e CC |
256 | ' |
257 | ||
258 | # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2 | |
259 | # so we should not be able to tell the first bad commit | |
260 | # among $HASH2, $HASH3 and $HASH4 | |
261 | test_expect_success 'bisect skip: cannot tell between 3 commits' ' | |
e4e6e8b4 | 262 | test_when_finished git bisect reset && |
97e1c51e | 263 | git bisect start $HASH4 $HASH1 && |
e4e6e8b4 JK |
264 | git bisect skip && |
265 | test_expect_code 2 git bisect skip >my_bisect_log.txt && | |
266 | grep "first bad commit could be any of" my_bisect_log.txt && | |
267 | ! grep $HASH1 my_bisect_log.txt && | |
268 | grep $HASH2 my_bisect_log.txt && | |
269 | grep $HASH3 my_bisect_log.txt && | |
270 | grep $HASH4 my_bisect_log.txt | |
97e1c51e CC |
271 | ' |
272 | ||
273 | # $HASH1 is good, $HASH4 is bad, we skip $HASH3 | |
274 | # but $HASH2 is good, | |
275 | # so we should not be able to tell the first bad commit | |
276 | # among $HASH3 and $HASH4 | |
277 | test_expect_success 'bisect skip: cannot tell between 2 commits' ' | |
e4e6e8b4 | 278 | test_when_finished git bisect reset && |
97e1c51e | 279 | git bisect start $HASH4 $HASH1 && |
e4e6e8b4 JK |
280 | git bisect skip && |
281 | test_expect_code 2 git bisect good >my_bisect_log.txt && | |
282 | grep "first bad commit could be any of" my_bisect_log.txt && | |
283 | ! grep $HASH1 my_bisect_log.txt && | |
284 | ! grep $HASH2 my_bisect_log.txt && | |
285 | grep $HASH3 my_bisect_log.txt && | |
286 | grep $HASH4 my_bisect_log.txt | |
97e1c51e CC |
287 | ' |
288 | ||
1b249ffe CC |
289 | # $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3 |
290 | # and $HASH2 is good, | |
291 | # so we should not be able to tell the first bad commit | |
292 | # among $HASH3 and $HASH4 | |
293 | test_expect_success 'bisect skip: with commit both bad and skipped' ' | |
e4e6e8b4 | 294 | test_when_finished git bisect reset && |
1b249ffe CC |
295 | git bisect start && |
296 | git bisect skip && | |
297 | git bisect bad && | |
298 | git bisect good $HASH1 && | |
299 | git bisect skip && | |
e4e6e8b4 JK |
300 | test_expect_code 2 git bisect good >my_bisect_log.txt && |
301 | grep "first bad commit could be any of" my_bisect_log.txt && | |
302 | ! grep $HASH1 my_bisect_log.txt && | |
303 | ! grep $HASH2 my_bisect_log.txt && | |
304 | grep $HASH3 my_bisect_log.txt && | |
305 | grep $HASH4 my_bisect_log.txt | |
97e1c51e CC |
306 | ' |
307 | ||
982fecf7 ÆAB |
308 | test_bisect_run_args () { |
309 | test_when_finished "rm -f run.sh actual" && | |
310 | >actual && | |
311 | cat >expect.args && | |
312 | cat <&6 >expect.out && | |
313 | cat <&7 >expect.err && | |
314 | write_script run.sh <<-\EOF && | |
315 | while test $# != 0 | |
316 | do | |
317 | echo "<$1>" && | |
318 | shift | |
319 | done >actual.args | |
320 | EOF | |
321 | ||
322 | test_when_finished "git bisect reset" && | |
323 | git bisect start && | |
324 | git bisect good $HASH1 && | |
325 | git bisect bad $HASH4 && | |
326 | git bisect run ./run.sh $@ >actual.out.raw 2>actual.err && | |
327 | # Prune just the log output | |
328 | sed -n \ | |
329 | -e '/^Author:/d' \ | |
330 | -e '/^Date:/d' \ | |
331 | -e '/^$/d' \ | |
332 | -e '/^commit /d' \ | |
333 | -e '/^ /d' \ | |
334 | -e 'p' \ | |
335 | <actual.out.raw >actual.out && | |
336 | test_cmp expect.out actual.out && | |
337 | test_cmp expect.err actual.err && | |
338 | test_cmp expect.args actual.args | |
339 | } | |
340 | ||
f37d0bdd | 341 | test_expect_success 'git bisect run: args, stdout and stderr with no arguments' " |
982fecf7 ÆAB |
342 | test_bisect_run_args <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' |
343 | EOF_ARGS | |
461fec41 | 344 | running './run.sh' |
982fecf7 | 345 | $HASH4 is the first bad commit |
461fec41 | 346 | bisect found first bad commit |
982fecf7 ÆAB |
347 | EOF_OUT |
348 | EOF_ERR | |
349 | " | |
350 | ||
f37d0bdd | 351 | test_expect_success 'git bisect run: args, stdout and stderr: "--" argument' " |
982fecf7 ÆAB |
352 | test_bisect_run_args -- <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' |
353 | <--> | |
354 | EOF_ARGS | |
461fec41 | 355 | running './run.sh' '--' |
982fecf7 | 356 | $HASH4 is the first bad commit |
461fec41 | 357 | bisect found first bad commit |
982fecf7 ÆAB |
358 | EOF_OUT |
359 | EOF_ERR | |
360 | " | |
361 | ||
f37d0bdd | 362 | test_expect_success 'git bisect run: args, stdout and stderr: "--log foo --no-log bar" arguments' " |
982fecf7 ÆAB |
363 | test_bisect_run_args --log foo --no-log bar <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' |
364 | <--log> | |
365 | <foo> | |
366 | <--no-log> | |
367 | <bar> | |
368 | EOF_ARGS | |
461fec41 | 369 | running './run.sh' '--log' 'foo' '--no-log' 'bar' |
982fecf7 | 370 | $HASH4 is the first bad commit |
461fec41 | 371 | bisect found first bad commit |
982fecf7 ÆAB |
372 | EOF_OUT |
373 | EOF_ERR | |
374 | " | |
375 | ||
f37d0bdd | 376 | test_expect_success 'git bisect run: args, stdout and stderr: "--bisect-start" argument' " |
982fecf7 ÆAB |
377 | test_bisect_run_args --bisect-start <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' |
378 | <--bisect-start> | |
379 | EOF_ARGS | |
461fec41 | 380 | running './run.sh' '--bisect-start' |
982fecf7 | 381 | $HASH4 is the first bad commit |
461fec41 | 382 | bisect found first bad commit |
982fecf7 ÆAB |
383 | EOF_OUT |
384 | EOF_ERR | |
385 | " | |
386 | ||
461fec41 ĐTCD |
387 | test_expect_success 'git bisect run: negative exit code' " |
388 | write_script fail.sh <<-'EOF' && | |
389 | exit 255 | |
390 | EOF | |
391 | cat <<-'EOF' >expect && | |
392 | bisect run failed: exit code -1 from './fail.sh' is < 0 or >= 128 | |
393 | EOF | |
394 | test_when_finished 'git bisect reset' && | |
395 | git bisect start && | |
396 | git bisect good $HASH1 && | |
397 | git bisect bad $HASH4 && | |
398 | ! git bisect run ./fail.sh 2>err && | |
399 | sed -En 's/.*(bisect.*code) (-?[0-9]+) (from.*)/\1 -1 \3/p' err >actual && | |
400 | test_cmp expect actual | |
401 | " | |
402 | ||
8962f8f8 | 403 | test_expect_success 'git bisect run: unable to verify on good' " |
461fec41 ĐTCD |
404 | write_script fail.sh <<-'EOF' && |
405 | head=\$(git rev-parse --verify HEAD) | |
406 | good=\$(git rev-parse --verify $HASH1) | |
407 | if test "\$head" = "\$good" | |
408 | then | |
409 | exit 255 | |
410 | else | |
411 | exit 127 | |
412 | fi | |
413 | EOF | |
414 | cat <<-'EOF' >expect && | |
415 | unable to verify './fail.sh' on good revision | |
416 | EOF | |
417 | test_when_finished 'git bisect reset' && | |
418 | git bisect start && | |
419 | git bisect good $HASH1 && | |
420 | git bisect bad $HASH4 && | |
421 | ! git bisect run ./fail.sh 2>err && | |
422 | sed -n 's/.*\(unable to verify.*\)/\1/p' err >actual && | |
423 | test_cmp expect actual | |
424 | " | |
425 | ||
a17c4101 | 426 | # We want to automatically find the commit that |
15a4802a AL |
427 | # added "Another" into hello. |
428 | test_expect_success '"git bisect run" simple case' ' | |
429 | write_script test_script.sh <<-\EOF && | |
430 | ! grep Another hello >/dev/null | |
431 | EOF | |
432 | git bisect start && | |
433 | git bisect good $HASH1 && | |
434 | git bisect bad $HASH4 && | |
435 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
436 | grep "$HASH3 is the first bad commit" my_bisect_log.txt && | |
437 | git bisect reset | |
438 | ' | |
38a47fd6 | 439 | |
e9011b60 ĐTCD |
440 | # We want to make sure no arguments has been eaten |
441 | test_expect_success '"git bisect run" simple case' ' | |
442 | git bisect start && | |
443 | git bisect good $HASH1 && | |
444 | git bisect bad $HASH4 && | |
445 | git bisect run printf "%s %s\n" reset --bisect-skip >my_bisect_log.txt && | |
446 | grep -e "reset --bisect-skip" my_bisect_log.txt && | |
447 | git bisect reset | |
448 | ' | |
449 | ||
38a47fd6 | 450 | # We want to automatically find the commit that |
15a4802a AL |
451 | # added "Ciao" into hello. |
452 | test_expect_success '"git bisect run" with more complex "git bisect start"' ' | |
453 | write_script test_script.sh <<-\EOF && | |
454 | ! grep Ciao hello >/dev/null | |
455 | EOF | |
456 | git bisect start $HASH4 $HASH1 && | |
457 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
458 | grep "$HASH4 is the first bad commit" my_bisect_log.txt && | |
459 | git bisect reset | |
460 | ' | |
a17c4101 | 461 | |
ba5bb815 RS |
462 | test_expect_success 'bisect run accepts exit code 126 as bad' ' |
463 | test_when_finished "git bisect reset" && | |
464 | write_script test_script.sh <<-\EOF && | |
465 | ! grep Another hello || exit 126 >/dev/null | |
466 | EOF | |
467 | git bisect start && | |
468 | git bisect good $HASH1 && | |
469 | git bisect bad $HASH4 && | |
470 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
471 | grep "$HASH3 is the first bad commit" my_bisect_log.txt | |
472 | ' | |
473 | ||
48af1fde | 474 | test_expect_success POSIXPERM 'bisect run fails with non-executable test script' ' |
ba5bb815 RS |
475 | test_when_finished "git bisect reset" && |
476 | >not-executable.sh && | |
477 | chmod -x not-executable.sh && | |
478 | git bisect start && | |
479 | git bisect good $HASH1 && | |
480 | git bisect bad $HASH4 && | |
481 | test_must_fail git bisect run ./not-executable.sh >my_bisect_log.txt && | |
482 | ! grep "is the first bad commit" my_bisect_log.txt | |
483 | ' | |
484 | ||
485 | test_expect_success 'bisect run accepts exit code 127 as bad' ' | |
486 | test_when_finished "git bisect reset" && | |
487 | write_script test_script.sh <<-\EOF && | |
488 | ! grep Another hello || exit 127 >/dev/null | |
489 | EOF | |
490 | git bisect start && | |
491 | git bisect good $HASH1 && | |
492 | git bisect bad $HASH4 && | |
493 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
494 | grep "$HASH3 is the first bad commit" my_bisect_log.txt | |
495 | ' | |
496 | ||
48af1fde | 497 | test_expect_success 'bisect run fails with missing test script' ' |
ba5bb815 RS |
498 | test_when_finished "git bisect reset" && |
499 | rm -f does-not-exist.sh && | |
500 | git bisect start && | |
501 | git bisect good $HASH1 && | |
502 | git bisect bad $HASH4 && | |
503 | test_must_fail git bisect run ./does-not-exist.sh >my_bisect_log.txt && | |
504 | ! grep "is the first bad commit" my_bisect_log.txt | |
505 | ' | |
506 | ||
97e1c51e CC |
507 | # $HASH1 is good, $HASH5 is bad, we skip $HASH3 |
508 | # but $HASH4 is good, | |
509 | # so we should find $HASH5 as the first bad commit | |
510 | HASH5= | |
511 | test_expect_success 'bisect skip: add line and then a new test' ' | |
512 | add_line_into_file "5: Another new line." hello && | |
513 | HASH5=$(git rev-parse --verify HEAD) && | |
514 | git bisect start $HASH5 $HASH1 && | |
515 | git bisect skip && | |
516 | git bisect good > my_bisect_log.txt && | |
21d0bc2f | 517 | grep "$HASH5 is the first bad commit" my_bisect_log.txt && |
fce0499f | 518 | git bisect log > log_to_replay.txt && |
37f9fd0d CC |
519 | git bisect reset |
520 | ' | |
521 | ||
522 | test_expect_success 'bisect skip and bisect replay' ' | |
523 | git bisect replay log_to_replay.txt > my_bisect_log.txt && | |
21d0bc2f | 524 | grep "$HASH5 is the first bad commit" my_bisect_log.txt && |
97e1c51e CC |
525 | git bisect reset |
526 | ' | |
527 | ||
71b0251c CC |
528 | HASH6= |
529 | test_expect_success 'bisect run & skip: cannot tell between 2' ' | |
530 | add_line_into_file "6: Yet a line." hello && | |
531 | HASH6=$(git rev-parse --verify HEAD) && | |
15a4802a AL |
532 | write_script test_script.sh <<-\EOF && |
533 | sed -ne \$p hello | grep Ciao >/dev/null && exit 125 | |
534 | ! grep line hello >/dev/null | |
535 | EOF | |
71b0251c | 536 | git bisect start $HASH6 $HASH1 && |
15a4802a AL |
537 | test_expect_code 2 git bisect run ./test_script.sh >my_bisect_log.txt && |
538 | grep "first bad commit could be any of" my_bisect_log.txt && | |
539 | ! grep $HASH3 my_bisect_log.txt && | |
540 | ! grep $HASH6 my_bisect_log.txt && | |
541 | grep $HASH4 my_bisect_log.txt && | |
542 | grep $HASH5 my_bisect_log.txt | |
71b0251c CC |
543 | ' |
544 | ||
545 | HASH7= | |
546 | test_expect_success 'bisect run & skip: find first bad' ' | |
547 | git bisect reset && | |
548 | add_line_into_file "7: Should be the last line." hello && | |
549 | HASH7=$(git rev-parse --verify HEAD) && | |
15a4802a AL |
550 | write_script test_script.sh <<-\EOF && |
551 | sed -ne \$p hello | grep Ciao >/dev/null && exit 125 | |
552 | sed -ne \$p hello | grep day >/dev/null && exit 125 | |
553 | ! grep Yet hello >/dev/null | |
554 | EOF | |
71b0251c | 555 | git bisect start $HASH7 $HASH1 && |
15a4802a | 556 | git bisect run ./test_script.sh >my_bisect_log.txt && |
21d0bc2f | 557 | grep "$HASH6 is the first bad commit" my_bisect_log.txt |
71b0251c CC |
558 | ' |
559 | ||
1a66a489 CC |
560 | test_expect_success 'bisect skip only one range' ' |
561 | git bisect reset && | |
562 | git bisect start $HASH7 $HASH1 && | |
563 | git bisect skip $HASH1..$HASH5 && | |
564 | test "$HASH6" = "$(git rev-parse --verify HEAD)" && | |
565 | test_must_fail git bisect bad > my_bisect_log.txt && | |
566 | grep "first bad commit could be any of" my_bisect_log.txt | |
567 | ' | |
ce32660e | 568 | |
1a66a489 CC |
569 | test_expect_success 'bisect skip many ranges' ' |
570 | git bisect start $HASH7 $HASH1 && | |
571 | test "$HASH4" = "$(git rev-parse --verify HEAD)" && | |
572 | git bisect skip $HASH2 $HASH2.. ..$HASH5 && | |
573 | test "$HASH6" = "$(git rev-parse --verify HEAD)" && | |
574 | test_must_fail git bisect bad > my_bisect_log.txt && | |
575 | grep "first bad commit could be any of" my_bisect_log.txt | |
576 | ' | |
577 | ||
578 | test_expect_success 'bisect starting with a detached HEAD' ' | |
ce32660e | 579 | git bisect reset && |
1550bb6e | 580 | git checkout main^ && |
ce32660e JS |
581 | HEAD=$(git rev-parse --verify HEAD) && |
582 | git bisect start && | |
b577bb92 | 583 | test $HEAD = $(cat .git/BISECT_START) && |
ce32660e JS |
584 | git bisect reset && |
585 | test $HEAD = $(git rev-parse --verify HEAD) | |
ee831f7d GP |
586 | ' |
587 | ||
42ba5ee7 CC |
588 | test_expect_success 'bisect errors out if bad and good are mistaken' ' |
589 | git bisect reset && | |
590 | test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error && | |
6789275d | 591 | test_grep "mistook good and bad" rev_list_error && |
42ba5ee7 CC |
592 | git bisect reset |
593 | ' | |
594 | ||
634f2464 CC |
595 | test_expect_success 'bisect does not create a "bisect" branch' ' |
596 | git bisect reset && | |
597 | git bisect start $HASH7 $HASH1 && | |
598 | git branch bisect && | |
599 | rev_hash4=$(git rev-parse --verify HEAD) && | |
600 | test "$rev_hash4" = "$HASH4" && | |
601 | git branch -D bisect && | |
602 | git bisect good && | |
603 | git branch bisect && | |
604 | rev_hash6=$(git rev-parse --verify HEAD) && | |
605 | test "$rev_hash6" = "$HASH6" && | |
606 | git bisect good > my_bisect_log.txt && | |
21d0bc2f | 607 | grep "$HASH7 is the first bad commit" my_bisect_log.txt && |
634f2464 CC |
608 | git bisect reset && |
609 | rev_hash6=$(git rev-parse --verify bisect) && | |
610 | test "$rev_hash6" = "$HASH6" && | |
611 | git branch -D bisect | |
612 | ' | |
613 | ||
f821d089 CC |
614 | # This creates a "side" branch to test "siblings" cases. |
615 | # | |
616 | # H1-H2-H3-H4-H5-H6-H7 <--other | |
617 | # \ | |
618 | # S5-S6-S7 <--side | |
619 | # | |
620 | test_expect_success 'side branch creation' ' | |
621 | git bisect reset && | |
622 | git checkout -b side $HASH4 && | |
623 | add_line_into_file "5(side): first line on a side branch" hello2 && | |
624 | SIDE_HASH5=$(git rev-parse --verify HEAD) && | |
625 | add_line_into_file "6(side): second line on a side branch" hello2 && | |
626 | SIDE_HASH6=$(git rev-parse --verify HEAD) && | |
627 | add_line_into_file "7(side): third line on a side branch" hello2 && | |
628 | SIDE_HASH7=$(git rev-parse --verify HEAD) | |
629 | ' | |
630 | ||
631 | test_expect_success 'good merge base when good and bad are siblings' ' | |
632 | git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt && | |
6789275d | 633 | test_grep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
634 | grep $HASH4 my_bisect_log.txt && |
635 | git bisect good > my_bisect_log.txt && | |
c7cf9566 | 636 | ! grep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
637 | grep $HASH6 my_bisect_log.txt && |
638 | git bisect reset | |
639 | ' | |
640 | test_expect_success 'skipped merge base when good and bad are siblings' ' | |
641 | git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt && | |
6789275d | 642 | test_grep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
643 | grep $HASH4 my_bisect_log.txt && |
644 | git bisect skip > my_bisect_log.txt 2>&1 && | |
bd757c18 | 645 | grep "warning" my_bisect_log.txt && |
f821d089 CC |
646 | grep $SIDE_HASH6 my_bisect_log.txt && |
647 | git bisect reset | |
648 | ' | |
649 | ||
650 | test_expect_success 'bad merge base when good and bad are siblings' ' | |
651 | git bisect start "$HASH7" HEAD > my_bisect_log.txt && | |
6789275d | 652 | test_grep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
653 | grep $HASH4 my_bisect_log.txt && |
654 | test_must_fail git bisect bad > my_bisect_log.txt 2>&1 && | |
6789275d JH |
655 | test_grep "merge base $HASH4 is bad" my_bisect_log.txt && |
656 | test_grep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt && | |
f821d089 CC |
657 | git bisect reset |
658 | ' | |
659 | ||
660 | # This creates a few more commits (A and B) to test "siblings" cases | |
661 | # when a good and a bad rev have many merge bases. | |
662 | # | |
663 | # We should have the following: | |
664 | # | |
665 | # H1-H2-H3-H4-H5-H6-H7 | |
666 | # \ \ \ | |
667 | # S5-A \ | |
668 | # \ \ | |
669 | # S6-S7----B | |
670 | # | |
671 | # And there A and B have 2 merge bases (S5 and H5) that should be | |
672 | # reported by "git merge-base --all A B". | |
673 | # | |
674 | test_expect_success 'many merge bases creation' ' | |
675 | git checkout "$SIDE_HASH5" && | |
676 | git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" && | |
677 | A_HASH=$(git rev-parse --verify HEAD) && | |
678 | git checkout side && | |
679 | git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" && | |
680 | B_HASH=$(git rev-parse --verify HEAD) && | |
681 | git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt && | |
3fb0459b | 682 | test_line_count = 2 merge_bases.txt && |
f821d089 CC |
683 | grep "$HASH5" merge_bases.txt && |
684 | grep "$SIDE_HASH5" merge_bases.txt | |
685 | ' | |
686 | ||
e8861ffc AL |
687 | # We want to automatically find the merge that |
688 | # added "line" into hello. | |
689 | test_expect_success '"git bisect run --first-parent" simple case' ' | |
690 | git rev-list --first-parent $B_HASH ^$HASH4 >first_parent_chain.txt && | |
691 | write_script test_script.sh <<-\EOF && | |
692 | grep $(git rev-parse HEAD) first_parent_chain.txt || exit -1 | |
693 | ! grep line hello >/dev/null | |
694 | EOF | |
695 | git bisect start --first-parent && | |
696 | test_path_is_file ".git/BISECT_FIRST_PARENT" && | |
697 | git bisect good $HASH4 && | |
698 | git bisect bad $B_HASH && | |
699 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
700 | grep "$B_HASH is the first bad commit" my_bisect_log.txt && | |
701 | git bisect reset && | |
702 | test_path_is_missing .git/BISECT_FIRST_PARENT | |
703 | ' | |
704 | ||
f821d089 CC |
705 | test_expect_success 'good merge bases when good and bad are siblings' ' |
706 | git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt && | |
6789275d | 707 | test_grep "merge base must be tested" my_bisect_log.txt && |
f821d089 | 708 | git bisect good > my_bisect_log2.txt && |
6789275d | 709 | test_grep "merge base must be tested" my_bisect_log2.txt && |
f821d089 CC |
710 | { |
711 | { | |
712 | grep "$SIDE_HASH5" my_bisect_log.txt && | |
713 | grep "$HASH5" my_bisect_log2.txt | |
714 | } || { | |
715 | grep "$SIDE_HASH5" my_bisect_log2.txt && | |
716 | grep "$HASH5" my_bisect_log.txt | |
717 | } | |
718 | } && | |
719 | git bisect reset | |
720 | ' | |
721 | ||
c9c4e2d5 | 722 | test_expect_success 'optimized merge base checks' ' |
c9c4e2d5 | 723 | git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt && |
6789275d | 724 | test_grep "merge base must be tested" my_bisect_log.txt && |
c9c4e2d5 | 725 | grep "$HASH4" my_bisect_log.txt && |
c9c4e2d5 CC |
726 | git bisect good > my_bisect_log2.txt && |
727 | test -f ".git/BISECT_ANCESTORS_OK" && | |
728 | test "$HASH6" = $(git rev-parse --verify HEAD) && | |
675ef6ba | 729 | git bisect bad && |
c9c4e2d5 | 730 | git bisect good "$A_HASH" > my_bisect_log4.txt && |
6789275d | 731 | test_grep "merge base must be tested" my_bisect_log4.txt && |
085ba9b5 | 732 | test_path_is_missing ".git/BISECT_ANCESTORS_OK" |
c9c4e2d5 CC |
733 | ' |
734 | ||
b74d7efb CC |
735 | # This creates another side branch called "parallel" with some files |
736 | # in some directories, to test bisecting with paths. | |
737 | # | |
738 | # We should have the following: | |
739 | # | |
740 | # P1-P2-P3-P4-P5-P6-P7 | |
741 | # / / / | |
742 | # H1-H2-H3-H4-H5-H6-H7 | |
743 | # \ \ \ | |
744 | # S5-A \ | |
745 | # \ \ | |
746 | # S6-S7----B | |
747 | # | |
748 | test_expect_success '"parallel" side branch creation' ' | |
749 | git bisect reset && | |
750 | git checkout -b parallel $HASH1 && | |
751 | mkdir dir1 dir2 && | |
752 | add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 && | |
753 | PARA_HASH1=$(git rev-parse --verify HEAD) && | |
754 | add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 && | |
755 | PARA_HASH2=$(git rev-parse --verify HEAD) && | |
756 | add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 && | |
a48fcd83 | 757 | PARA_HASH3=$(git rev-parse --verify HEAD) && |
b74d7efb | 758 | git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" && |
a48fcd83 | 759 | PARA_HASH4=$(git rev-parse --verify HEAD) && |
b74d7efb | 760 | add_line_into_file "5(para): add line on parallel branch" dir1/file1 && |
a48fcd83 | 761 | PARA_HASH5=$(git rev-parse --verify HEAD) && |
b74d7efb | 762 | add_line_into_file "6(para): add line on parallel branch" dir2/file2 && |
a48fcd83 | 763 | PARA_HASH6=$(git rev-parse --verify HEAD) && |
b74d7efb CC |
764 | git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" && |
765 | PARA_HASH7=$(git rev-parse --verify HEAD) | |
766 | ' | |
767 | ||
768 | test_expect_success 'restricting bisection on one dir' ' | |
769 | git bisect reset && | |
770 | git bisect start HEAD $HASH1 -- dir1 && | |
771 | para1=$(git rev-parse --verify HEAD) && | |
772 | test "$para1" = "$PARA_HASH1" && | |
773 | git bisect bad > my_bisect_log.txt && | |
21d0bc2f | 774 | grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt |
b74d7efb CC |
775 | ' |
776 | ||
777 | test_expect_success 'restricting bisection on one dir and a file' ' | |
778 | git bisect reset && | |
779 | git bisect start HEAD $HASH1 -- dir1 hello && | |
780 | para4=$(git rev-parse --verify HEAD) && | |
781 | test "$para4" = "$PARA_HASH4" && | |
782 | git bisect bad && | |
783 | hash3=$(git rev-parse --verify HEAD) && | |
784 | test "$hash3" = "$HASH3" && | |
785 | git bisect good && | |
786 | hash4=$(git rev-parse --verify HEAD) && | |
787 | test "$hash4" = "$HASH4" && | |
788 | git bisect good && | |
789 | para1=$(git rev-parse --verify HEAD) && | |
790 | test "$para1" = "$PARA_HASH1" && | |
791 | git bisect good > my_bisect_log.txt && | |
21d0bc2f | 792 | grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt |
b74d7efb CC |
793 | ' |
794 | ||
a66037c9 CC |
795 | test_expect_success 'skipping away from skipped commit' ' |
796 | git bisect start $PARA_HASH7 $HASH1 && | |
797 | para4=$(git rev-parse --verify HEAD) && | |
798 | test "$para4" = "$PARA_HASH4" && | |
799 | git bisect skip && | |
800 | hash7=$(git rev-parse --verify HEAD) && | |
801 | test "$hash7" = "$HASH7" && | |
802 | git bisect skip && | |
ebc9529f CC |
803 | para3=$(git rev-parse --verify HEAD) && |
804 | test "$para3" = "$PARA_HASH3" | |
a66037c9 CC |
805 | ' |
806 | ||
b8657347 | 807 | test_expect_success 'erroring out when using bad path arguments' ' |
8f69f72f | 808 | test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt && |
6789275d | 809 | test_grep "bad path arguments" error.txt |
8f69f72f CC |
810 | ' |
811 | ||
24c51280 JS |
812 | test_expect_success 'test bisection on bare repo - --no-checkout specified' ' |
813 | git clone --bare . bare.nocheckout && | |
814 | ( | |
815 | cd bare.nocheckout && | |
816 | git bisect start --no-checkout && | |
817 | git bisect good $HASH1 && | |
818 | git bisect bad $HASH4 && | |
819 | git bisect run eval \ | |
820 | "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \ | |
e4e6e8b4 | 821 | >../nocheckout.log |
24c51280 JS |
822 | ) && |
823 | grep "$HASH3 is the first bad commit" nocheckout.log | |
824 | ' | |
825 | ||
826 | ||
827 | test_expect_success 'test bisection on bare repo - --no-checkout defaulted' ' | |
828 | git clone --bare . bare.defaulted && | |
829 | ( | |
830 | cd bare.defaulted && | |
831 | git bisect start && | |
832 | git bisect good $HASH1 && | |
833 | git bisect bad $HASH4 && | |
834 | git bisect run eval \ | |
835 | "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \ | |
e4e6e8b4 | 836 | >../defaulted.log |
24c51280 JS |
837 | ) && |
838 | grep "$HASH3 is the first bad commit" defaulted.log | |
839 | ' | |
840 | ||
a17c4101 | 841 | # |
d3dfeedf JS |
842 | # This creates a broken branch which cannot be checked out because |
843 | # the tree created has been deleted. | |
a17c4101 | 844 | # |
d3dfeedf JS |
845 | # H1-H2-H3-H4-H5-H6-H7 <--other |
846 | # \ | |
847 | # S5-S6'-S7'-S8'-S9 <--broken | |
848 | # | |
849 | # Commits marked with ' have a missing tree. | |
850 | # | |
851 | test_expect_success 'broken branch creation' ' | |
852 | git bisect reset && | |
853 | git checkout -b broken $HASH4 && | |
854 | git tag BROKEN_HASH4 $HASH4 && | |
855 | add_line_into_file "5(broken): first line on a broken branch" hello2 && | |
856 | git tag BROKEN_HASH5 && | |
857 | mkdir missing && | |
858 | :> missing/MISSING && | |
859 | git add missing/MISSING && | |
e4e6e8b4 | 860 | git commit -m "6(broken): Added file that will be deleted" && |
d3dfeedf | 861 | git tag BROKEN_HASH6 && |
0795aed0 | 862 | deleted=$(git rev-parse --verify HEAD:missing) && |
d3dfeedf JS |
863 | add_line_into_file "7(broken): second line on a broken branch" hello2 && |
864 | git tag BROKEN_HASH7 && | |
865 | add_line_into_file "8(broken): third line on a broken branch" hello2 && | |
866 | git tag BROKEN_HASH8 && | |
867 | git rm missing/MISSING && | |
e4e6e8b4 | 868 | git commit -m "9(broken): Remove missing file" && |
d3dfeedf | 869 | git tag BROKEN_HASH9 && |
0795aed0 | 870 | rm .git/objects/$(test_oid_to_path $deleted) |
d3dfeedf JS |
871 | ' |
872 | ||
873 | echo "" > expected.ok | |
874 | cat > expected.missing-tree.default <<EOF | |
0795aed0 | 875 | fatal: unable to read tree $deleted |
d3dfeedf JS |
876 | EOF |
877 | ||
878 | test_expect_success 'bisect fails if tree is broken on start commit' ' | |
879 | git bisect reset && | |
880 | test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt && | |
881 | test_cmp expected.missing-tree.default error.txt | |
882 | ' | |
883 | ||
884 | test_expect_success 'bisect fails if tree is broken on trial commit' ' | |
885 | git bisect reset && | |
886 | test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt && | |
887 | git reset --hard broken && | |
888 | git checkout broken && | |
889 | test_cmp expected.missing-tree.default error.txt | |
890 | ' | |
891 | ||
b704a8b3 JS |
892 | check_same() |
893 | { | |
894 | echo "Checking $1 is the same as $2" && | |
5d77298d | 895 | test_cmp_rev "$1" "$2" |
b704a8b3 JS |
896 | } |
897 | ||
898 | test_expect_success 'bisect: --no-checkout - start commit bad' ' | |
899 | git bisect reset && | |
900 | git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout && | |
901 | check_same BROKEN_HASH6 BISECT_HEAD && | |
902 | git bisect reset | |
903 | ' | |
904 | ||
905 | test_expect_success 'bisect: --no-checkout - trial commit bad' ' | |
906 | git bisect reset && | |
907 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
908 | check_same BROKEN_HASH6 BISECT_HEAD && | |
909 | git bisect reset | |
910 | ' | |
911 | ||
912 | test_expect_success 'bisect: --no-checkout - target before breakage' ' | |
913 | git bisect reset && | |
914 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
915 | check_same BROKEN_HASH6 BISECT_HEAD && | |
916 | git bisect bad BISECT_HEAD && | |
917 | check_same BROKEN_HASH5 BISECT_HEAD && | |
918 | git bisect bad BISECT_HEAD && | |
919 | check_same BROKEN_HASH5 bisect/bad && | |
920 | git bisect reset | |
921 | ' | |
922 | ||
923 | test_expect_success 'bisect: --no-checkout - target in breakage' ' | |
924 | git bisect reset && | |
925 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
926 | check_same BROKEN_HASH6 BISECT_HEAD && | |
927 | git bisect bad BISECT_HEAD && | |
928 | check_same BROKEN_HASH5 BISECT_HEAD && | |
b02be8b9 | 929 | test_must_fail git bisect good BISECT_HEAD && |
b704a8b3 JS |
930 | check_same BROKEN_HASH6 bisect/bad && |
931 | git bisect reset | |
932 | ' | |
933 | ||
934 | test_expect_success 'bisect: --no-checkout - target after breakage' ' | |
935 | git bisect reset && | |
936 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
937 | check_same BROKEN_HASH6 BISECT_HEAD && | |
938 | git bisect good BISECT_HEAD && | |
939 | check_same BROKEN_HASH8 BISECT_HEAD && | |
b02be8b9 | 940 | test_must_fail git bisect good BISECT_HEAD && |
b704a8b3 JS |
941 | check_same BROKEN_HASH9 bisect/bad && |
942 | git bisect reset | |
943 | ' | |
944 | ||
945 | test_expect_success 'bisect: demonstrate identification of damage boundary' " | |
946 | git bisect reset && | |
947 | git checkout broken && | |
1550bb6e | 948 | git bisect start broken main --no-checkout && |
b02be8b9 | 949 | test_must_fail git bisect run \"\$SHELL_PATH\" -c ' |
b704a8b3 JS |
950 | GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) && |
951 | git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ && | |
952 | git pack-objects --stdout >/dev/null < tmp.\$\$ | |
953 | rc=\$? | |
954 | rm -f tmp.\$\$ | |
955 | test \$rc = 0' && | |
956 | check_same BROKEN_HASH6 bisect/bad && | |
957 | git bisect reset | |
958 | " | |
959 | ||
a7f8b8ac | 960 | cat > expected.bisect-log <<EOF |
0795aed0 | 961 | # bad: [$HASH4] Add <4: Ciao for now> into <hello>. |
962 | # good: [$HASH2] Add <2: A new day for git> into <hello>. | |
963 | git bisect start '$HASH4' '$HASH2' | |
964 | # good: [$HASH3] Add <3: Another new day for git> into <hello>. | |
965 | git bisect good $HASH3 | |
966 | # first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>. | |
a7f8b8ac TH |
967 | EOF |
968 | ||
2e3a16b2 | 969 | test_expect_success 'bisect log: successful result' ' |
a7f8b8ac TH |
970 | git bisect reset && |
971 | git bisect start $HASH4 $HASH2 && | |
972 | git bisect good && | |
973 | git bisect log >bisect-log.txt && | |
974 | test_cmp expected.bisect-log bisect-log.txt && | |
975 | git bisect reset | |
976 | ' | |
977 | ||
f989cac9 | 978 | cat > expected.bisect-skip-log <<EOF |
0795aed0 | 979 | # bad: [$HASH4] Add <4: Ciao for now> into <hello>. |
980 | # good: [$HASH2] Add <2: A new day for git> into <hello>. | |
981 | git bisect start '$HASH4' '$HASH2' | |
982 | # skip: [$HASH3] Add <3: Another new day for git> into <hello>. | |
983 | git bisect skip $HASH3 | |
f989cac9 | 984 | # only skipped commits left to test |
0795aed0 | 985 | # possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>. |
986 | # possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>. | |
f989cac9 TH |
987 | EOF |
988 | ||
989 | test_expect_success 'bisect log: only skip commits left' ' | |
990 | git bisect reset && | |
991 | git bisect start $HASH4 $HASH2 && | |
992 | test_must_fail git bisect skip && | |
993 | git bisect log >bisect-skip-log.txt && | |
994 | test_cmp expected.bisect-skip-log bisect-skip-log.txt && | |
995 | git bisect reset | |
996 | ' | |
997 | ||
07913d5a CC |
998 | test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' ' |
999 | git checkout parallel && | |
1000 | git bisect start HEAD $HASH1 && | |
1001 | git bisect good HEAD && | |
1002 | git bisect bad HEAD && | |
1003 | test "$HASH6" = $(git rev-parse --verify HEAD) && | |
1004 | git bisect reset | |
1005 | ' | |
1006 | ||
21e5cfd8 AD |
1007 | test_expect_success 'bisect starts with only one new' ' |
1008 | git bisect reset && | |
1009 | git bisect start && | |
1010 | git bisect new $HASH4 && | |
1011 | git bisect next | |
1012 | ' | |
1013 | ||
1014 | test_expect_success 'bisect does not start with only one old' ' | |
1015 | git bisect reset && | |
1016 | git bisect start && | |
1017 | git bisect old $HASH1 && | |
1018 | test_must_fail git bisect next | |
1019 | ' | |
1020 | ||
1021 | test_expect_success 'bisect start with one new and old' ' | |
1022 | git bisect reset && | |
1023 | git bisect start && | |
1024 | git bisect old $HASH1 && | |
1025 | git bisect new $HASH4 && | |
1026 | git bisect new && | |
1027 | git bisect new >bisect_result && | |
1028 | grep "$HASH2 is the first new commit" bisect_result && | |
1029 | git bisect log >log_to_replay.txt && | |
1030 | git bisect reset | |
1031 | ' | |
1032 | ||
1033 | test_expect_success 'bisect replay with old and new' ' | |
1034 | git bisect replay log_to_replay.txt >bisect_result && | |
1035 | grep "$HASH2 is the first new commit" bisect_result && | |
1036 | git bisect reset | |
1037 | ' | |
1038 | ||
6c722cbe CW |
1039 | test_expect_success 'bisect replay with CRLF log' ' |
1040 | append_cr <log_to_replay.txt >log_to_replay_crlf.txt && | |
1041 | git bisect replay log_to_replay_crlf.txt >bisect_result_crlf && | |
1042 | grep "$HASH2 is the first new commit" bisect_result_crlf && | |
1043 | git bisect reset | |
1044 | ' | |
1045 | ||
21e5cfd8 AD |
1046 | test_expect_success 'bisect cannot mix old/new and good/bad' ' |
1047 | git bisect start && | |
1048 | git bisect bad $HASH4 && | |
1049 | test_must_fail git bisect old $HASH1 | |
1050 | ' | |
1051 | ||
21b55e33 MM |
1052 | test_expect_success 'bisect terms needs 0 or 1 argument' ' |
1053 | git bisect reset && | |
1054 | test_must_fail git bisect terms only-one && | |
1055 | test_must_fail git bisect terms 1 2 && | |
1056 | test_must_fail git bisect terms 2>actual && | |
450ebb73 | 1057 | echo "error: no terms defined" >expected && |
1108cea7 | 1058 | test_cmp expected actual |
21b55e33 MM |
1059 | ' |
1060 | ||
1061 | test_expect_success 'bisect terms shows good/bad after start' ' | |
1062 | git bisect reset && | |
1063 | git bisect start HEAD $HASH1 && | |
1064 | git bisect terms --term-good >actual && | |
1065 | echo good >expected && | |
1066 | test_cmp expected actual && | |
1067 | git bisect terms --term-bad >actual && | |
1068 | echo bad >expected && | |
1069 | test_cmp expected actual | |
1070 | ' | |
1071 | ||
06e6a745 MM |
1072 | test_expect_success 'bisect start with one term1 and term2' ' |
1073 | git bisect reset && | |
1074 | git bisect start --term-old term2 --term-new term1 && | |
1075 | git bisect term2 $HASH1 && | |
1076 | git bisect term1 $HASH4 && | |
1077 | git bisect term1 && | |
1078 | git bisect term1 >bisect_result && | |
1079 | grep "$HASH2 is the first term1 commit" bisect_result && | |
1080 | git bisect log >log_to_replay.txt && | |
1081 | git bisect reset | |
1082 | ' | |
1083 | ||
2f645b33 JS |
1084 | test_expect_success 'bogus command does not start bisect' ' |
1085 | git bisect reset && | |
1086 | test_must_fail git bisect --bisect-terms 1 2 2>out && | |
1087 | ! grep "You need to start" out && | |
1088 | test_must_fail git bisect --bisect-terms 2>out && | |
1089 | ! grep "You need to start" out && | |
1090 | grep "git bisect.*visualize" out && | |
1091 | git bisect reset | |
1092 | ' | |
1093 | ||
06e6a745 MM |
1094 | test_expect_success 'bisect replay with term1 and term2' ' |
1095 | git bisect replay log_to_replay.txt >bisect_result && | |
1096 | grep "$HASH2 is the first term1 commit" bisect_result && | |
1097 | git bisect reset | |
1098 | ' | |
1099 | ||
1100 | test_expect_success 'bisect start term1 term2' ' | |
1101 | git bisect reset && | |
1102 | git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 && | |
1103 | git bisect term1 && | |
1104 | git bisect term1 >bisect_result && | |
1105 | grep "$HASH2 is the first term1 commit" bisect_result && | |
1106 | git bisect log >log_to_replay.txt && | |
1107 | git bisect reset | |
1108 | ' | |
1109 | ||
1110 | test_expect_success 'bisect cannot mix terms' ' | |
1111 | git bisect reset && | |
1112 | git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 && | |
1113 | test_must_fail git bisect a && | |
1114 | test_must_fail git bisect b && | |
1115 | test_must_fail git bisect bad && | |
1116 | test_must_fail git bisect good && | |
1117 | test_must_fail git bisect new && | |
1118 | test_must_fail git bisect old | |
1119 | ' | |
1120 | ||
1121 | test_expect_success 'bisect terms rejects invalid terms' ' | |
1122 | git bisect reset && | |
4d9005ff | 1123 | test_must_fail git bisect start --term-good && |
06e6a745 | 1124 | test_must_fail git bisect start --term-good invalid..term && |
4d9005ff | 1125 | test_must_fail git bisect start --term-bad && |
06e6a745 MM |
1126 | test_must_fail git bisect terms --term-bad invalid..term && |
1127 | test_must_fail git bisect terms --term-good bad && | |
1128 | test_must_fail git bisect terms --term-good old && | |
1129 | test_must_fail git bisect terms --term-good skip && | |
1130 | test_must_fail git bisect terms --term-good reset && | |
1131 | test_path_is_missing .git/BISECT_TERMS | |
1132 | ' | |
1133 | ||
1134 | test_expect_success 'bisect start --term-* does store terms' ' | |
1135 | git bisect reset && | |
1136 | git bisect start --term-bad=one --term-good=two && | |
1137 | git bisect terms >actual && | |
1138 | cat <<-EOF >expected && | |
1139 | Your current terms are two for the old state | |
1140 | and one for the new state. | |
1141 | EOF | |
1108cea7 | 1142 | test_cmp expected actual && |
06e6a745 MM |
1143 | git bisect terms --term-bad >actual && |
1144 | echo one >expected && | |
1145 | test_cmp expected actual && | |
1146 | git bisect terms --term-good >actual && | |
1147 | echo two >expected && | |
1148 | test_cmp expected actual | |
1149 | ' | |
1150 | ||
1151 | test_expect_success 'bisect start takes options and revs in any order' ' | |
1152 | git bisect reset && | |
1153 | git bisect start --term-good one $HASH4 \ | |
1154 | --term-good two --term-bad bad-term \ | |
1155 | $HASH1 --term-good three -- && | |
1156 | (git bisect terms --term-bad && git bisect terms --term-good) >actual && | |
1157 | printf "%s\n%s\n" bad-term three >expected && | |
1158 | test_cmp expected actual | |
1159 | ' | |
1160 | ||
4cd66e7d RJ |
1161 | # Bisect is started with --term-new and --term-old arguments, |
1162 | # then skip. The HEAD should be changed. | |
1163 | test_expect_success 'bisect skip works with --term*' ' | |
1164 | git bisect reset && | |
1165 | git bisect start --term-new=fixed --term-old=unfixed HEAD $HASH1 && | |
1166 | hash_skipped_from=$(git rev-parse --verify HEAD) && | |
1167 | git bisect skip && | |
1168 | hash_skipped_to=$(git rev-parse --verify HEAD) && | |
1169 | test "$hash_skipped_from" != "$hash_skipped_to" | |
1170 | ' | |
1171 | ||
ba7eafe1 PB |
1172 | test_expect_success 'git bisect reset cleans bisection state properly' ' |
1173 | git bisect reset && | |
1174 | git bisect start && | |
1175 | git bisect good $HASH1 && | |
1176 | git bisect bad $HASH4 && | |
1177 | git bisect reset && | |
1178 | test -z "$(git for-each-ref "refs/bisect/*")" && | |
33fc5625 FC |
1179 | test_path_is_missing ".git/BISECT_EXPECTED_REV" && |
1180 | test_path_is_missing ".git/BISECT_ANCESTORS_OK" && | |
1181 | test_path_is_missing ".git/BISECT_LOG" && | |
1182 | test_path_is_missing ".git/BISECT_RUN" && | |
1183 | test_path_is_missing ".git/BISECT_TERMS" && | |
33fc5625 FC |
1184 | test_path_is_missing ".git/BISECT_HEAD" && |
1185 | test_path_is_missing ".git/BISECT_START" | |
ba7eafe1 PB |
1186 | ' |
1187 | ||
7730f855 JK |
1188 | test_expect_success 'bisect handles annotated tags' ' |
1189 | test_commit commit-one && | |
1190 | git tag -m foo tag-one && | |
1191 | test_commit commit-two && | |
1192 | git tag -m foo tag-two && | |
1193 | git bisect start && | |
1194 | git bisect good tag-one && | |
1195 | git bisect bad tag-two >output && | |
1196 | bad=$(git rev-parse --verify tag-two^{commit}) && | |
1197 | grep "$bad is the first bad commit" output | |
1198 | ' | |
1199 | ||
282073cc MR |
1200 | test_expect_success 'bisect run fails with exit code equals or greater than 128' ' |
1201 | write_script test_script.sh <<-\EOF && | |
1202 | exit 128 | |
1203 | EOF | |
1204 | test_must_fail git bisect run ./test_script.sh && | |
1205 | write_script test_script.sh <<-\EOF && | |
1206 | exit 255 | |
1207 | EOF | |
1208 | test_must_fail git bisect run ./test_script.sh | |
1209 | ' | |
1210 | ||
5fe973b9 MR |
1211 | test_expect_success 'bisect visualize with a filename with dash and space' ' |
1212 | echo "My test line" >>"./-hello 2" && | |
1213 | git add -- "./-hello 2" && | |
1214 | git commit --quiet -m "Add test line" -- "./-hello 2" && | |
1215 | git bisect visualize -p -- "-hello 2" | |
1216 | ' | |
1217 | ||
0cf1defa CD |
1218 | test_expect_success 'bisect state output with multiple good commits' ' |
1219 | git bisect reset && | |
1220 | git bisect start >output && | |
1221 | grep "waiting for both good and bad commits" output && | |
f11046e6 CD |
1222 | git bisect log >output && |
1223 | grep "waiting for both good and bad commits" output && | |
0cf1defa CD |
1224 | git bisect good "$HASH1" >output && |
1225 | grep "waiting for bad commit, 1 good commit known" output && | |
f11046e6 CD |
1226 | git bisect log >output && |
1227 | grep "waiting for bad commit, 1 good commit known" output && | |
0cf1defa | 1228 | git bisect good "$HASH2" >output && |
f11046e6 CD |
1229 | grep "waiting for bad commit, 2 good commits known" output && |
1230 | git bisect log >output && | |
0cf1defa CD |
1231 | grep "waiting for bad commit, 2 good commits known" output |
1232 | ' | |
1233 | ||
1234 | test_expect_success 'bisect state output with bad commit' ' | |
1235 | git bisect reset && | |
1236 | git bisect start >output && | |
1237 | grep "waiting for both good and bad commits" output && | |
f11046e6 CD |
1238 | git bisect log >output && |
1239 | grep "waiting for both good and bad commits" output && | |
0cf1defa | 1240 | git bisect bad "$HASH4" >output && |
f11046e6 CD |
1241 | grep -F "waiting for good commit(s), bad commit known" output && |
1242 | git bisect log >output && | |
0cf1defa CD |
1243 | grep -F "waiting for good commit(s), bad commit known" output |
1244 | ' | |
1245 | ||
4de06fbd JS |
1246 | test_expect_success 'verify correct error message' ' |
1247 | git bisect reset && | |
1248 | git bisect start $HASH4 $HASH1 && | |
1249 | write_script test_script.sh <<-\EOF && | |
1250 | rm .git/BISECT* | |
1251 | EOF | |
1252 | test_must_fail git bisect run ./test_script.sh 2>error && | |
1253 | grep "git bisect good.*exited with error code" error | |
1254 | ' | |
1255 | ||
a17c4101 | 1256 | test_done |