clone_submodule: avoid using `access()` on directories
[git.git] / t / t6030-bisect-porcelain.sh
blob6dbbe62eb2203c4c12619463e01e438d0bfa93bc
1 #!/bin/sh
3 # Copyright (c) 2007 Christian Couder
5 test_description='Tests git bisect functionality'
7 exec </dev/null
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 . ./test-lib.sh
14 add_line_into_file()
16 _line=$1
17 _file=$2
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."
28 test_tick
29 git commit --quiet -m "$MSG" $_file
32 HASH1=
33 HASH2=
34 HASH3=
35 HASH4=
37 test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' '
38 add_line_into_file "1: Hello World" hello &&
39 HASH1=$(git rev-parse --verify HEAD) &&
40 add_line_into_file "2: A new day for git" hello &&
41 HASH2=$(git rev-parse --verify HEAD) &&
42 add_line_into_file "3: Another new day for git" hello &&
43 HASH3=$(git rev-parse --verify HEAD) &&
44 add_line_into_file "4: Ciao for now" hello &&
45 HASH4=$(git rev-parse --verify HEAD)
48 test_expect_success 'bisect starts with only one bad' '
49 git bisect reset &&
50 git bisect start &&
51 git bisect bad $HASH4 &&
52 git bisect next
55 test_expect_success 'bisect does not start with only one good' '
56 git bisect reset &&
57 git bisect start &&
58 git bisect good $HASH1 &&
59 test_must_fail git bisect next
62 test_expect_success 'bisect start with one bad and good' '
63 git bisect reset &&
64 git bisect start &&
65 git bisect good $HASH1 &&
66 git bisect bad $HASH4 &&
67 git bisect next
70 test_expect_success 'bisect fails if given any junk instead of revs' '
71 git bisect reset &&
72 test_must_fail git bisect start foo $HASH1 -- &&
73 test_must_fail git bisect start $HASH4 $HASH1 bar -- &&
74 test -z "$(git for-each-ref "refs/bisect/*")" &&
75 test -z "$(ls .git/BISECT_* 2>/dev/null)" &&
76 git bisect start &&
77 test_must_fail git bisect good foo $HASH1 &&
78 test_must_fail git bisect good $HASH1 bar &&
79 test_must_fail git bisect bad frotz &&
80 test_must_fail git bisect bad $HASH3 $HASH4 &&
81 test_must_fail git bisect skip bar $HASH3 &&
82 test_must_fail git bisect skip $HASH1 foo &&
83 test -z "$(git for-each-ref "refs/bisect/*")" &&
84 git bisect good $HASH1 &&
85 git bisect bad $HASH4
88 test_expect_success 'bisect start without -- takes unknown arg as pathspec' '
89 git bisect reset &&
90 git bisect start foo bar &&
91 grep foo ".git/BISECT_NAMES" &&
92 grep bar ".git/BISECT_NAMES"
95 test_expect_success 'bisect reset: back in the main branch' '
96 git bisect reset &&
97 echo "* main" > branch.expect &&
98 git branch > branch.output &&
99 cmp branch.expect branch.output
102 test_expect_success 'bisect reset: back in another branch' '
103 git checkout -b other &&
104 git bisect start &&
105 git bisect good $HASH1 &&
106 git bisect bad $HASH3 &&
107 git bisect reset &&
108 echo " main" > branch.expect &&
109 echo "* other" >> branch.expect &&
110 git branch > branch.output &&
111 cmp branch.expect branch.output
114 test_expect_success 'bisect reset when not bisecting' '
115 git bisect reset &&
116 git branch > branch.output &&
117 cmp branch.expect branch.output
120 test_expect_success 'bisect reset removes packed refs' '
121 git bisect reset &&
122 git bisect start &&
123 git bisect good $HASH1 &&
124 git bisect bad $HASH3 &&
125 git pack-refs --all --prune &&
126 git bisect next &&
127 git bisect reset &&
128 test -z "$(git for-each-ref "refs/bisect/*")" &&
129 test -z "$(git for-each-ref "refs/heads/bisect")"
132 test_expect_success 'bisect reset removes bisect state after --no-checkout' '
133 git bisect reset &&
134 git bisect start --no-checkout &&
135 git bisect good $HASH1 &&
136 git bisect bad $HASH3 &&
137 git bisect next &&
138 git bisect reset &&
139 test -z "$(git for-each-ref "refs/bisect/*")" &&
140 test -z "$(git for-each-ref "refs/heads/bisect")" &&
141 test -z "$(git for-each-ref "BISECT_HEAD")"
144 test_expect_success 'bisect start: back in good branch' '
145 git branch > branch.output &&
146 grep "* other" branch.output > /dev/null &&
147 git bisect start $HASH4 $HASH1 -- &&
148 git bisect good &&
149 git bisect start $HASH4 $HASH1 -- &&
150 git bisect bad &&
151 git bisect reset &&
152 git branch > branch.output &&
153 grep "* other" branch.output > /dev/null
156 test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' '
157 git bisect reset &&
158 test_must_fail git bisect start $HASH4 foo -- &&
159 git branch > branch.output &&
160 grep "* other" branch.output > /dev/null &&
161 test_path_is_missing .git/BISECT_START
164 test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
165 git bisect start $HASH4 $HASH1 -- &&
166 git bisect good &&
167 cp .git/BISECT_START saved &&
168 test_must_fail git bisect start $HASH4 foo -- &&
169 git branch > branch.output &&
170 test_i18ngrep "* (no branch, bisect started on other)" branch.output > /dev/null &&
171 test_cmp saved .git/BISECT_START
173 test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
174 git bisect start $HASH4 $HASH1 -- &&
175 git bisect good &&
176 test_must_fail git bisect start $HASH1 $HASH4 -- &&
177 git branch > branch.output &&
178 grep "* other" branch.output > /dev/null &&
179 test_path_is_missing .git/BISECT_START
182 test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
183 echo "temp stuff" > hello &&
184 test_must_fail git bisect start $HASH4 $HASH1 -- &&
185 git branch &&
186 git branch > branch.output &&
187 grep "* other" branch.output > /dev/null &&
188 test_path_is_missing .git/BISECT_START &&
189 test -z "$(git for-each-ref "refs/bisect/*")" &&
190 git checkout HEAD hello
193 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
194 # but $HASH2 is bad,
195 # so we should find $HASH2 as the first bad commit
196 test_expect_success 'bisect skip: successful result' '
197 test_when_finished git bisect reset &&
198 git bisect reset &&
199 git bisect start $HASH4 $HASH1 &&
200 git bisect skip &&
201 git bisect bad > my_bisect_log.txt &&
202 grep "$HASH2 is the first bad commit" my_bisect_log.txt
205 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
206 # so we should not be able to tell the first bad commit
207 # among $HASH2, $HASH3 and $HASH4
208 test_expect_success 'bisect skip: cannot tell between 3 commits' '
209 test_when_finished git bisect reset &&
210 git bisect start $HASH4 $HASH1 &&
211 git bisect skip &&
212 test_expect_code 2 git bisect skip >my_bisect_log.txt &&
213 grep "first bad commit could be any of" my_bisect_log.txt &&
214 ! grep $HASH1 my_bisect_log.txt &&
215 grep $HASH2 my_bisect_log.txt &&
216 grep $HASH3 my_bisect_log.txt &&
217 grep $HASH4 my_bisect_log.txt
220 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
221 # but $HASH2 is good,
222 # so we should not be able to tell the first bad commit
223 # among $HASH3 and $HASH4
224 test_expect_success 'bisect skip: cannot tell between 2 commits' '
225 test_when_finished git bisect reset &&
226 git bisect start $HASH4 $HASH1 &&
227 git bisect skip &&
228 test_expect_code 2 git bisect good >my_bisect_log.txt &&
229 grep "first bad commit could be any of" my_bisect_log.txt &&
230 ! grep $HASH1 my_bisect_log.txt &&
231 ! grep $HASH2 my_bisect_log.txt &&
232 grep $HASH3 my_bisect_log.txt &&
233 grep $HASH4 my_bisect_log.txt
236 # $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
237 # and $HASH2 is good,
238 # so we should not be able to tell the first bad commit
239 # among $HASH3 and $HASH4
240 test_expect_success 'bisect skip: with commit both bad and skipped' '
241 test_when_finished git bisect reset &&
242 git bisect start &&
243 git bisect skip &&
244 git bisect bad &&
245 git bisect good $HASH1 &&
246 git bisect skip &&
247 test_expect_code 2 git bisect good >my_bisect_log.txt &&
248 grep "first bad commit could be any of" my_bisect_log.txt &&
249 ! grep $HASH1 my_bisect_log.txt &&
250 ! grep $HASH2 my_bisect_log.txt &&
251 grep $HASH3 my_bisect_log.txt &&
252 grep $HASH4 my_bisect_log.txt
255 # We want to automatically find the commit that
256 # added "Another" into hello.
257 test_expect_success '"git bisect run" simple case' '
258 write_script test_script.sh <<-\EOF &&
259 ! grep Another hello >/dev/null
261 git bisect start &&
262 git bisect good $HASH1 &&
263 git bisect bad $HASH4 &&
264 git bisect run ./test_script.sh >my_bisect_log.txt &&
265 grep "$HASH3 is the first bad commit" my_bisect_log.txt &&
266 git bisect reset
269 # We want to make sure no arguments has been eaten
270 test_expect_success '"git bisect run" simple case' '
271 git bisect start &&
272 git bisect good $HASH1 &&
273 git bisect bad $HASH4 &&
274 git bisect run printf "%s %s\n" reset --bisect-skip >my_bisect_log.txt &&
275 grep -e "reset --bisect-skip" my_bisect_log.txt &&
276 git bisect reset
279 # We want to automatically find the commit that
280 # added "Ciao" into hello.
281 test_expect_success '"git bisect run" with more complex "git bisect start"' '
282 write_script test_script.sh <<-\EOF &&
283 ! grep Ciao hello >/dev/null
285 git bisect start $HASH4 $HASH1 &&
286 git bisect run ./test_script.sh >my_bisect_log.txt &&
287 grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
288 git bisect reset
291 test_expect_success 'bisect run accepts exit code 126 as bad' '
292 test_when_finished "git bisect reset" &&
293 write_script test_script.sh <<-\EOF &&
294 ! grep Another hello || exit 126 >/dev/null
296 git bisect start &&
297 git bisect good $HASH1 &&
298 git bisect bad $HASH4 &&
299 git bisect run ./test_script.sh >my_bisect_log.txt &&
300 grep "$HASH3 is the first bad commit" my_bisect_log.txt
303 test_expect_success POSIXPERM 'bisect run fails with non-executable test script' '
304 test_when_finished "git bisect reset" &&
305 >not-executable.sh &&
306 chmod -x not-executable.sh &&
307 git bisect start &&
308 git bisect good $HASH1 &&
309 git bisect bad $HASH4 &&
310 test_must_fail git bisect run ./not-executable.sh >my_bisect_log.txt &&
311 ! grep "is the first bad commit" my_bisect_log.txt
314 test_expect_success 'bisect run accepts exit code 127 as bad' '
315 test_when_finished "git bisect reset" &&
316 write_script test_script.sh <<-\EOF &&
317 ! grep Another hello || exit 127 >/dev/null
319 git bisect start &&
320 git bisect good $HASH1 &&
321 git bisect bad $HASH4 &&
322 git bisect run ./test_script.sh >my_bisect_log.txt &&
323 grep "$HASH3 is the first bad commit" my_bisect_log.txt
326 test_expect_success 'bisect run fails with missing test script' '
327 test_when_finished "git bisect reset" &&
328 rm -f does-not-exist.sh &&
329 git bisect start &&
330 git bisect good $HASH1 &&
331 git bisect bad $HASH4 &&
332 test_must_fail git bisect run ./does-not-exist.sh >my_bisect_log.txt &&
333 ! grep "is the first bad commit" my_bisect_log.txt
336 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
337 # but $HASH4 is good,
338 # so we should find $HASH5 as the first bad commit
339 HASH5=
340 test_expect_success 'bisect skip: add line and then a new test' '
341 add_line_into_file "5: Another new line." hello &&
342 HASH5=$(git rev-parse --verify HEAD) &&
343 git bisect start $HASH5 $HASH1 &&
344 git bisect skip &&
345 git bisect good > my_bisect_log.txt &&
346 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
347 git bisect log > log_to_replay.txt &&
348 git bisect reset
351 test_expect_success 'bisect skip and bisect replay' '
352 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
353 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
354 git bisect reset
357 HASH6=
358 test_expect_success 'bisect run & skip: cannot tell between 2' '
359 add_line_into_file "6: Yet a line." hello &&
360 HASH6=$(git rev-parse --verify HEAD) &&
361 write_script test_script.sh <<-\EOF &&
362 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
363 ! grep line hello >/dev/null
365 git bisect start $HASH6 $HASH1 &&
366 test_expect_code 2 git bisect run ./test_script.sh >my_bisect_log.txt &&
367 grep "first bad commit could be any of" my_bisect_log.txt &&
368 ! grep $HASH3 my_bisect_log.txt &&
369 ! grep $HASH6 my_bisect_log.txt &&
370 grep $HASH4 my_bisect_log.txt &&
371 grep $HASH5 my_bisect_log.txt
374 HASH7=
375 test_expect_success 'bisect run & skip: find first bad' '
376 git bisect reset &&
377 add_line_into_file "7: Should be the last line." hello &&
378 HASH7=$(git rev-parse --verify HEAD) &&
379 write_script test_script.sh <<-\EOF &&
380 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
381 sed -ne \$p hello | grep day >/dev/null && exit 125
382 ! grep Yet hello >/dev/null
384 git bisect start $HASH7 $HASH1 &&
385 git bisect run ./test_script.sh >my_bisect_log.txt &&
386 grep "$HASH6 is the first bad commit" my_bisect_log.txt
389 test_expect_success 'bisect skip only one range' '
390 git bisect reset &&
391 git bisect start $HASH7 $HASH1 &&
392 git bisect skip $HASH1..$HASH5 &&
393 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
394 test_must_fail git bisect bad > my_bisect_log.txt &&
395 grep "first bad commit could be any of" my_bisect_log.txt
398 test_expect_success 'bisect skip many ranges' '
399 git bisect start $HASH7 $HASH1 &&
400 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
401 git bisect skip $HASH2 $HASH2.. ..$HASH5 &&
402 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
403 test_must_fail git bisect bad > my_bisect_log.txt &&
404 grep "first bad commit could be any of" my_bisect_log.txt
407 test_expect_success 'bisect starting with a detached HEAD' '
408 git bisect reset &&
409 git checkout main^ &&
410 HEAD=$(git rev-parse --verify HEAD) &&
411 git bisect start &&
412 test $HEAD = $(cat .git/BISECT_START) &&
413 git bisect reset &&
414 test $HEAD = $(git rev-parse --verify HEAD)
417 test_expect_success 'bisect errors out if bad and good are mistaken' '
418 git bisect reset &&
419 test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
420 test_i18ngrep "mistook good and bad" rev_list_error &&
421 git bisect reset
424 test_expect_success 'bisect does not create a "bisect" branch' '
425 git bisect reset &&
426 git bisect start $HASH7 $HASH1 &&
427 git branch bisect &&
428 rev_hash4=$(git rev-parse --verify HEAD) &&
429 test "$rev_hash4" = "$HASH4" &&
430 git branch -D bisect &&
431 git bisect good &&
432 git branch bisect &&
433 rev_hash6=$(git rev-parse --verify HEAD) &&
434 test "$rev_hash6" = "$HASH6" &&
435 git bisect good > my_bisect_log.txt &&
436 grep "$HASH7 is the first bad commit" my_bisect_log.txt &&
437 git bisect reset &&
438 rev_hash6=$(git rev-parse --verify bisect) &&
439 test "$rev_hash6" = "$HASH6" &&
440 git branch -D bisect
443 # This creates a "side" branch to test "siblings" cases.
445 # H1-H2-H3-H4-H5-H6-H7 <--other
447 # S5-S6-S7 <--side
449 test_expect_success 'side branch creation' '
450 git bisect reset &&
451 git checkout -b side $HASH4 &&
452 add_line_into_file "5(side): first line on a side branch" hello2 &&
453 SIDE_HASH5=$(git rev-parse --verify HEAD) &&
454 add_line_into_file "6(side): second line on a side branch" hello2 &&
455 SIDE_HASH6=$(git rev-parse --verify HEAD) &&
456 add_line_into_file "7(side): third line on a side branch" hello2 &&
457 SIDE_HASH7=$(git rev-parse --verify HEAD)
460 test_expect_success 'good merge base when good and bad are siblings' '
461 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
462 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
463 grep $HASH4 my_bisect_log.txt &&
464 git bisect good > my_bisect_log.txt &&
465 ! grep "merge base must be tested" my_bisect_log.txt &&
466 grep $HASH6 my_bisect_log.txt &&
467 git bisect reset
469 test_expect_success 'skipped merge base when good and bad are siblings' '
470 git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt &&
471 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
472 grep $HASH4 my_bisect_log.txt &&
473 git bisect skip > my_bisect_log.txt 2>&1 &&
474 grep "warning" my_bisect_log.txt &&
475 grep $SIDE_HASH6 my_bisect_log.txt &&
476 git bisect reset
479 test_expect_success 'bad merge base when good and bad are siblings' '
480 git bisect start "$HASH7" HEAD > my_bisect_log.txt &&
481 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
482 grep $HASH4 my_bisect_log.txt &&
483 test_must_fail git bisect bad > my_bisect_log.txt 2>&1 &&
484 test_i18ngrep "merge base $HASH4 is bad" my_bisect_log.txt &&
485 test_i18ngrep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt &&
486 git bisect reset
489 # This creates a few more commits (A and B) to test "siblings" cases
490 # when a good and a bad rev have many merge bases.
492 # We should have the following:
494 # H1-H2-H3-H4-H5-H6-H7
495 # \ \ \
496 # S5-A \
497 # \ \
498 # S6-S7----B
500 # And there A and B have 2 merge bases (S5 and H5) that should be
501 # reported by "git merge-base --all A B".
503 test_expect_success 'many merge bases creation' '
504 git checkout "$SIDE_HASH5" &&
505 git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" &&
506 A_HASH=$(git rev-parse --verify HEAD) &&
507 git checkout side &&
508 git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" &&
509 B_HASH=$(git rev-parse --verify HEAD) &&
510 git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt &&
511 test_line_count = 2 merge_bases.txt &&
512 grep "$HASH5" merge_bases.txt &&
513 grep "$SIDE_HASH5" merge_bases.txt
516 # We want to automatically find the merge that
517 # added "line" into hello.
518 test_expect_success '"git bisect run --first-parent" simple case' '
519 git rev-list --first-parent $B_HASH ^$HASH4 >first_parent_chain.txt &&
520 write_script test_script.sh <<-\EOF &&
521 grep $(git rev-parse HEAD) first_parent_chain.txt || exit -1
522 ! grep line hello >/dev/null
524 git bisect start --first-parent &&
525 test_path_is_file ".git/BISECT_FIRST_PARENT" &&
526 git bisect good $HASH4 &&
527 git bisect bad $B_HASH &&
528 git bisect run ./test_script.sh >my_bisect_log.txt &&
529 grep "$B_HASH is the first bad commit" my_bisect_log.txt &&
530 git bisect reset &&
531 test_path_is_missing .git/BISECT_FIRST_PARENT
534 test_expect_success 'good merge bases when good and bad are siblings' '
535 git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt &&
536 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
537 git bisect good > my_bisect_log2.txt &&
538 test_i18ngrep "merge base must be tested" my_bisect_log2.txt &&
541 grep "$SIDE_HASH5" my_bisect_log.txt &&
542 grep "$HASH5" my_bisect_log2.txt
543 } || {
544 grep "$SIDE_HASH5" my_bisect_log2.txt &&
545 grep "$HASH5" my_bisect_log.txt
547 } &&
548 git bisect reset
551 test_expect_success 'optimized merge base checks' '
552 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
553 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
554 grep "$HASH4" my_bisect_log.txt &&
555 git bisect good > my_bisect_log2.txt &&
556 test -f ".git/BISECT_ANCESTORS_OK" &&
557 test "$HASH6" = $(git rev-parse --verify HEAD) &&
558 git bisect bad &&
559 git bisect good "$A_HASH" > my_bisect_log4.txt &&
560 test_i18ngrep "merge base must be tested" my_bisect_log4.txt &&
561 test_path_is_missing ".git/BISECT_ANCESTORS_OK"
564 # This creates another side branch called "parallel" with some files
565 # in some directories, to test bisecting with paths.
567 # We should have the following:
569 # P1-P2-P3-P4-P5-P6-P7
570 # / / /
571 # H1-H2-H3-H4-H5-H6-H7
572 # \ \ \
573 # S5-A \
574 # \ \
575 # S6-S7----B
577 test_expect_success '"parallel" side branch creation' '
578 git bisect reset &&
579 git checkout -b parallel $HASH1 &&
580 mkdir dir1 dir2 &&
581 add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 &&
582 PARA_HASH1=$(git rev-parse --verify HEAD) &&
583 add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
584 PARA_HASH2=$(git rev-parse --verify HEAD) &&
585 add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
586 PARA_HASH3=$(git rev-parse --verify HEAD) &&
587 git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
588 PARA_HASH4=$(git rev-parse --verify HEAD) &&
589 add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
590 PARA_HASH5=$(git rev-parse --verify HEAD) &&
591 add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
592 PARA_HASH6=$(git rev-parse --verify HEAD) &&
593 git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
594 PARA_HASH7=$(git rev-parse --verify HEAD)
597 test_expect_success 'restricting bisection on one dir' '
598 git bisect reset &&
599 git bisect start HEAD $HASH1 -- dir1 &&
600 para1=$(git rev-parse --verify HEAD) &&
601 test "$para1" = "$PARA_HASH1" &&
602 git bisect bad > my_bisect_log.txt &&
603 grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
606 test_expect_success 'restricting bisection on one dir and a file' '
607 git bisect reset &&
608 git bisect start HEAD $HASH1 -- dir1 hello &&
609 para4=$(git rev-parse --verify HEAD) &&
610 test "$para4" = "$PARA_HASH4" &&
611 git bisect bad &&
612 hash3=$(git rev-parse --verify HEAD) &&
613 test "$hash3" = "$HASH3" &&
614 git bisect good &&
615 hash4=$(git rev-parse --verify HEAD) &&
616 test "$hash4" = "$HASH4" &&
617 git bisect good &&
618 para1=$(git rev-parse --verify HEAD) &&
619 test "$para1" = "$PARA_HASH1" &&
620 git bisect good > my_bisect_log.txt &&
621 grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
624 test_expect_success 'skipping away from skipped commit' '
625 git bisect start $PARA_HASH7 $HASH1 &&
626 para4=$(git rev-parse --verify HEAD) &&
627 test "$para4" = "$PARA_HASH4" &&
628 git bisect skip &&
629 hash7=$(git rev-parse --verify HEAD) &&
630 test "$hash7" = "$HASH7" &&
631 git bisect skip &&
632 para3=$(git rev-parse --verify HEAD) &&
633 test "$para3" = "$PARA_HASH3"
636 test_expect_success 'erroring out when using bad path arguments' '
637 test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
638 test_i18ngrep "bad path arguments" error.txt
641 test_expect_success 'test bisection on bare repo - --no-checkout specified' '
642 git clone --bare . bare.nocheckout &&
644 cd bare.nocheckout &&
645 git bisect start --no-checkout &&
646 git bisect good $HASH1 &&
647 git bisect bad $HASH4 &&
648 git bisect run eval \
649 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
650 >../nocheckout.log
651 ) &&
652 grep "$HASH3 is the first bad commit" nocheckout.log
656 test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
657 git clone --bare . bare.defaulted &&
659 cd bare.defaulted &&
660 git bisect start &&
661 git bisect good $HASH1 &&
662 git bisect bad $HASH4 &&
663 git bisect run eval \
664 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
665 >../defaulted.log
666 ) &&
667 grep "$HASH3 is the first bad commit" defaulted.log
671 # This creates a broken branch which cannot be checked out because
672 # the tree created has been deleted.
674 # H1-H2-H3-H4-H5-H6-H7 <--other
676 # S5-S6'-S7'-S8'-S9 <--broken
678 # Commits marked with ' have a missing tree.
680 test_expect_success 'broken branch creation' '
681 git bisect reset &&
682 git checkout -b broken $HASH4 &&
683 git tag BROKEN_HASH4 $HASH4 &&
684 add_line_into_file "5(broken): first line on a broken branch" hello2 &&
685 git tag BROKEN_HASH5 &&
686 mkdir missing &&
687 :> missing/MISSING &&
688 git add missing/MISSING &&
689 git commit -m "6(broken): Added file that will be deleted" &&
690 git tag BROKEN_HASH6 &&
691 deleted=$(git rev-parse --verify HEAD:missing) &&
692 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
693 git tag BROKEN_HASH7 &&
694 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
695 git tag BROKEN_HASH8 &&
696 git rm missing/MISSING &&
697 git commit -m "9(broken): Remove missing file" &&
698 git tag BROKEN_HASH9 &&
699 rm .git/objects/$(test_oid_to_path $deleted)
702 echo "" > expected.ok
703 cat > expected.missing-tree.default <<EOF
704 fatal: unable to read tree $deleted
707 test_expect_success 'bisect fails if tree is broken on start commit' '
708 git bisect reset &&
709 test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
710 test_cmp expected.missing-tree.default error.txt
713 test_expect_success 'bisect fails if tree is broken on trial commit' '
714 git bisect reset &&
715 test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
716 git reset --hard broken &&
717 git checkout broken &&
718 test_cmp expected.missing-tree.default error.txt
721 check_same()
723 echo "Checking $1 is the same as $2" &&
724 test_cmp_rev "$1" "$2"
727 test_expect_success 'bisect: --no-checkout - start commit bad' '
728 git bisect reset &&
729 git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
730 check_same BROKEN_HASH6 BISECT_HEAD &&
731 git bisect reset
734 test_expect_success 'bisect: --no-checkout - trial commit bad' '
735 git bisect reset &&
736 git bisect start broken BROKEN_HASH4 --no-checkout &&
737 check_same BROKEN_HASH6 BISECT_HEAD &&
738 git bisect reset
741 test_expect_success 'bisect: --no-checkout - target before breakage' '
742 git bisect reset &&
743 git bisect start broken BROKEN_HASH4 --no-checkout &&
744 check_same BROKEN_HASH6 BISECT_HEAD &&
745 git bisect bad BISECT_HEAD &&
746 check_same BROKEN_HASH5 BISECT_HEAD &&
747 git bisect bad BISECT_HEAD &&
748 check_same BROKEN_HASH5 bisect/bad &&
749 git bisect reset
752 test_expect_success 'bisect: --no-checkout - target in breakage' '
753 git bisect reset &&
754 git bisect start broken BROKEN_HASH4 --no-checkout &&
755 check_same BROKEN_HASH6 BISECT_HEAD &&
756 git bisect bad BISECT_HEAD &&
757 check_same BROKEN_HASH5 BISECT_HEAD &&
758 test_must_fail git bisect good BISECT_HEAD &&
759 check_same BROKEN_HASH6 bisect/bad &&
760 git bisect reset
763 test_expect_success 'bisect: --no-checkout - target after breakage' '
764 git bisect reset &&
765 git bisect start broken BROKEN_HASH4 --no-checkout &&
766 check_same BROKEN_HASH6 BISECT_HEAD &&
767 git bisect good BISECT_HEAD &&
768 check_same BROKEN_HASH8 BISECT_HEAD &&
769 test_must_fail git bisect good BISECT_HEAD &&
770 check_same BROKEN_HASH9 bisect/bad &&
771 git bisect reset
774 test_expect_success 'bisect: demonstrate identification of damage boundary' "
775 git bisect reset &&
776 git checkout broken &&
777 git bisect start broken main --no-checkout &&
778 test_must_fail git bisect run \"\$SHELL_PATH\" -c '
779 GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
780 git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
781 git pack-objects --stdout >/dev/null < tmp.\$\$
782 rc=\$?
783 rm -f tmp.\$\$
784 test \$rc = 0' &&
785 check_same BROKEN_HASH6 bisect/bad &&
786 git bisect reset
789 cat > expected.bisect-log <<EOF
790 # bad: [$HASH4] Add <4: Ciao for now> into <hello>.
791 # good: [$HASH2] Add <2: A new day for git> into <hello>.
792 git bisect start '$HASH4' '$HASH2'
793 # good: [$HASH3] Add <3: Another new day for git> into <hello>.
794 git bisect good $HASH3
795 # first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
798 test_expect_success 'bisect log: successful result' '
799 git bisect reset &&
800 git bisect start $HASH4 $HASH2 &&
801 git bisect good &&
802 git bisect log >bisect-log.txt &&
803 test_cmp expected.bisect-log bisect-log.txt &&
804 git bisect reset
807 cat > expected.bisect-skip-log <<EOF
808 # bad: [$HASH4] Add <4: Ciao for now> into <hello>.
809 # good: [$HASH2] Add <2: A new day for git> into <hello>.
810 git bisect start '$HASH4' '$HASH2'
811 # skip: [$HASH3] Add <3: Another new day for git> into <hello>.
812 git bisect skip $HASH3
813 # only skipped commits left to test
814 # possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
815 # possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>.
818 test_expect_success 'bisect log: only skip commits left' '
819 git bisect reset &&
820 git bisect start $HASH4 $HASH2 &&
821 test_must_fail git bisect skip &&
822 git bisect log >bisect-skip-log.txt &&
823 test_cmp expected.bisect-skip-log bisect-skip-log.txt &&
824 git bisect reset
827 test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' '
828 git checkout parallel &&
829 git bisect start HEAD $HASH1 &&
830 git bisect good HEAD &&
831 git bisect bad HEAD &&
832 test "$HASH6" = $(git rev-parse --verify HEAD) &&
833 git bisect reset
836 test_expect_success 'bisect starts with only one new' '
837 git bisect reset &&
838 git bisect start &&
839 git bisect new $HASH4 &&
840 git bisect next
843 test_expect_success 'bisect does not start with only one old' '
844 git bisect reset &&
845 git bisect start &&
846 git bisect old $HASH1 &&
847 test_must_fail git bisect next
850 test_expect_success 'bisect start with one new and old' '
851 git bisect reset &&
852 git bisect start &&
853 git bisect old $HASH1 &&
854 git bisect new $HASH4 &&
855 git bisect new &&
856 git bisect new >bisect_result &&
857 grep "$HASH2 is the first new commit" bisect_result &&
858 git bisect log >log_to_replay.txt &&
859 git bisect reset
862 test_expect_success 'bisect replay with old and new' '
863 git bisect replay log_to_replay.txt >bisect_result &&
864 grep "$HASH2 is the first new commit" bisect_result &&
865 git bisect reset
868 test_expect_success 'bisect replay with CRLF log' '
869 append_cr <log_to_replay.txt >log_to_replay_crlf.txt &&
870 git bisect replay log_to_replay_crlf.txt >bisect_result_crlf &&
871 grep "$HASH2 is the first new commit" bisect_result_crlf &&
872 git bisect reset
875 test_expect_success 'bisect cannot mix old/new and good/bad' '
876 git bisect start &&
877 git bisect bad $HASH4 &&
878 test_must_fail git bisect old $HASH1
881 test_expect_success 'bisect terms needs 0 or 1 argument' '
882 git bisect reset &&
883 test_must_fail git bisect terms only-one &&
884 test_must_fail git bisect terms 1 2 &&
885 test_must_fail git bisect terms 2>actual &&
886 echo "error: no terms defined" >expected &&
887 test_cmp expected actual
890 test_expect_success 'bisect terms shows good/bad after start' '
891 git bisect reset &&
892 git bisect start HEAD $HASH1 &&
893 git bisect terms --term-good >actual &&
894 echo good >expected &&
895 test_cmp expected actual &&
896 git bisect terms --term-bad >actual &&
897 echo bad >expected &&
898 test_cmp expected actual
901 test_expect_success 'bisect start with one term1 and term2' '
902 git bisect reset &&
903 git bisect start --term-old term2 --term-new term1 &&
904 git bisect term2 $HASH1 &&
905 git bisect term1 $HASH4 &&
906 git bisect term1 &&
907 git bisect term1 >bisect_result &&
908 grep "$HASH2 is the first term1 commit" bisect_result &&
909 git bisect log >log_to_replay.txt &&
910 git bisect reset
913 test_expect_success 'bisect replay with term1 and term2' '
914 git bisect replay log_to_replay.txt >bisect_result &&
915 grep "$HASH2 is the first term1 commit" bisect_result &&
916 git bisect reset
919 test_expect_success 'bisect start term1 term2' '
920 git bisect reset &&
921 git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
922 git bisect term1 &&
923 git bisect term1 >bisect_result &&
924 grep "$HASH2 is the first term1 commit" bisect_result &&
925 git bisect log >log_to_replay.txt &&
926 git bisect reset
929 test_expect_success 'bisect cannot mix terms' '
930 git bisect reset &&
931 git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 &&
932 test_must_fail git bisect a &&
933 test_must_fail git bisect b &&
934 test_must_fail git bisect bad &&
935 test_must_fail git bisect good &&
936 test_must_fail git bisect new &&
937 test_must_fail git bisect old
940 test_expect_success 'bisect terms rejects invalid terms' '
941 git bisect reset &&
942 test_must_fail git bisect start --term-good &&
943 test_must_fail git bisect start --term-good invalid..term &&
944 test_must_fail git bisect start --term-bad &&
945 test_must_fail git bisect terms --term-bad invalid..term &&
946 test_must_fail git bisect terms --term-good bad &&
947 test_must_fail git bisect terms --term-good old &&
948 test_must_fail git bisect terms --term-good skip &&
949 test_must_fail git bisect terms --term-good reset &&
950 test_path_is_missing .git/BISECT_TERMS
953 test_expect_success 'bisect start --term-* does store terms' '
954 git bisect reset &&
955 git bisect start --term-bad=one --term-good=two &&
956 git bisect terms >actual &&
957 cat <<-EOF >expected &&
958 Your current terms are two for the old state
959 and one for the new state.
961 test_cmp expected actual &&
962 git bisect terms --term-bad >actual &&
963 echo one >expected &&
964 test_cmp expected actual &&
965 git bisect terms --term-good >actual &&
966 echo two >expected &&
967 test_cmp expected actual
970 test_expect_success 'bisect start takes options and revs in any order' '
971 git bisect reset &&
972 git bisect start --term-good one $HASH4 \
973 --term-good two --term-bad bad-term \
974 $HASH1 --term-good three -- &&
975 (git bisect terms --term-bad && git bisect terms --term-good) >actual &&
976 printf "%s\n%s\n" bad-term three >expected &&
977 test_cmp expected actual
980 # Bisect is started with --term-new and --term-old arguments,
981 # then skip. The HEAD should be changed.
982 test_expect_success 'bisect skip works with --term*' '
983 git bisect reset &&
984 git bisect start --term-new=fixed --term-old=unfixed HEAD $HASH1 &&
985 hash_skipped_from=$(git rev-parse --verify HEAD) &&
986 git bisect skip &&
987 hash_skipped_to=$(git rev-parse --verify HEAD) &&
988 test "$hash_skipped_from" != "$hash_skipped_to"
991 test_expect_success 'git bisect reset cleans bisection state properly' '
992 git bisect reset &&
993 git bisect start &&
994 git bisect good $HASH1 &&
995 git bisect bad $HASH4 &&
996 git bisect reset &&
997 test -z "$(git for-each-ref "refs/bisect/*")" &&
998 test_path_is_missing ".git/BISECT_EXPECTED_REV" &&
999 test_path_is_missing ".git/BISECT_ANCESTORS_OK" &&
1000 test_path_is_missing ".git/BISECT_LOG" &&
1001 test_path_is_missing ".git/BISECT_RUN" &&
1002 test_path_is_missing ".git/BISECT_TERMS" &&
1003 test_path_is_missing ".git/head-name" &&
1004 test_path_is_missing ".git/BISECT_HEAD" &&
1005 test_path_is_missing ".git/BISECT_START"
1008 test_expect_success 'bisect handles annotated tags' '
1009 test_commit commit-one &&
1010 git tag -m foo tag-one &&
1011 test_commit commit-two &&
1012 git tag -m foo tag-two &&
1013 git bisect start &&
1014 git bisect good tag-one &&
1015 git bisect bad tag-two >output &&
1016 bad=$(git rev-parse --verify tag-two^{commit}) &&
1017 grep "$bad is the first bad commit" output
1020 test_expect_success 'bisect run fails with exit code equals or greater than 128' '
1021 write_script test_script.sh <<-\EOF &&
1022 exit 128
1024 test_must_fail git bisect run ./test_script.sh &&
1025 write_script test_script.sh <<-\EOF &&
1026 exit 255
1028 test_must_fail git bisect run ./test_script.sh
1031 test_expect_success 'bisect visualize with a filename with dash and space' '
1032 echo "My test line" >>"./-hello 2" &&
1033 git add -- "./-hello 2" &&
1034 git commit --quiet -m "Add test line" -- "./-hello 2" &&
1035 git bisect visualize -p -- "-hello 2"
1038 test_expect_success 'bisect state output with multiple good commits' '
1039 git bisect reset &&
1040 git bisect start >output &&
1041 grep "waiting for both good and bad commits" output &&
1042 git bisect log >output &&
1043 grep "waiting for both good and bad commits" output &&
1044 git bisect good "$HASH1" >output &&
1045 grep "waiting for bad commit, 1 good commit known" output &&
1046 git bisect log >output &&
1047 grep "waiting for bad commit, 1 good commit known" output &&
1048 git bisect good "$HASH2" >output &&
1049 grep "waiting for bad commit, 2 good commits known" output &&
1050 git bisect log >output &&
1051 grep "waiting for bad commit, 2 good commits known" output
1054 test_expect_success 'bisect state output with bad commit' '
1055 git bisect reset &&
1056 git bisect start >output &&
1057 grep "waiting for both good and bad commits" output &&
1058 git bisect log >output &&
1059 grep "waiting for both good and bad commits" output &&
1060 git bisect bad "$HASH4" >output &&
1061 grep -F "waiting for good commit(s), bad commit known" output &&
1062 git bisect log >output &&
1063 grep -F "waiting for good commit(s), bad commit known" output
1066 test_done