3 # Copyright (c) 2007 Christian Couder
5 test_description='Tests git bisect functionality'
16 if [ -f "$_file" ]; then
17 echo "$_line" >> $_file || return $?
18 MSG="Add <$_line> into <$_file>."
20 echo "$_line" > $_file || return $?
21 git add $_file || return $?
22 MSG="Create file <$_file> with <$_line> inside."
26 git commit --quiet -m "$MSG" $_file
34 test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' '
35 add_line_into_file "1: Hello World" hello &&
36 HASH1=$(git rev-parse --verify HEAD) &&
37 add_line_into_file "2: A new day for git" hello &&
38 HASH2=$(git rev-parse --verify HEAD) &&
39 add_line_into_file "3: Another new day for git" hello &&
40 HASH3=$(git rev-parse --verify HEAD) &&
41 add_line_into_file "4: Ciao for now" hello &&
42 HASH4=$(git rev-parse --verify HEAD)
45 test_expect_success 'bisect starts with only one bad' '
48 git bisect bad $HASH4 &&
52 test_expect_success 'bisect does not start with only one good' '
55 git bisect good $HASH1 &&
56 test_must_fail git bisect next
59 test_expect_success 'bisect start with one bad and good' '
62 git bisect good $HASH1 &&
63 git bisect bad $HASH4 &&
67 test_expect_success 'bisect fails if given any junk instead of revs' '
69 test_must_fail git bisect start foo $HASH1 -- &&
70 test_must_fail git bisect start $HASH4 $HASH1 bar -- &&
71 test -z "$(git for-each-ref "refs/bisect/*")" &&
72 test -z "$(ls .git/BISECT_* 2>/dev/null)" &&
74 test_must_fail git bisect good foo $HASH1 &&
75 test_must_fail git bisect good $HASH1 bar &&
76 test_must_fail git bisect bad frotz &&
77 test_must_fail git bisect bad $HASH3 $HASH4 &&
78 test_must_fail git bisect skip bar $HASH3 &&
79 test_must_fail git bisect skip $HASH1 foo &&
80 test -z "$(git for-each-ref "refs/bisect/*")" &&
81 git bisect good $HASH1 &&
85 test_expect_success 'bisect start without -- takes unknown arg as pathspec' '
87 git bisect start foo bar &&
88 grep foo ".git/BISECT_NAMES" &&
89 grep bar ".git/BISECT_NAMES"
92 test_expect_success 'bisect reset: back in the master branch' '
94 echo "* master" > branch.expect &&
95 git branch > branch.output &&
96 cmp branch.expect branch.output
99 test_expect_success 'bisect reset: back in another branch' '
100 git checkout -b other &&
102 git bisect good $HASH1 &&
103 git bisect bad $HASH3 &&
105 echo " master" > branch.expect &&
106 echo "* other" >> branch.expect &&
107 git branch > branch.output &&
108 cmp branch.expect branch.output
111 test_expect_success 'bisect reset when not bisecting' '
113 git branch > branch.output &&
114 cmp branch.expect branch.output
117 test_expect_success 'bisect reset removes packed refs' '
120 git bisect good $HASH1 &&
121 git bisect bad $HASH3 &&
122 git pack-refs --all --prune &&
125 test -z "$(git for-each-ref "refs/bisect/*")" &&
126 test -z "$(git for-each-ref "refs/heads/bisect")"
129 test_expect_success 'bisect reset removes bisect state after --no-checkout' '
131 git bisect start --no-checkout &&
132 git bisect good $HASH1 &&
133 git bisect bad $HASH3 &&
136 test -z "$(git for-each-ref "refs/bisect/*")" &&
137 test -z "$(git for-each-ref "refs/heads/bisect")" &&
138 test -z "$(git for-each-ref "BISECT_HEAD")"
141 test_expect_success 'bisect start: back in good branch' '
142 git branch > branch.output &&
143 grep "* other" branch.output > /dev/null &&
144 git bisect start $HASH4 $HASH1 -- &&
146 git bisect start $HASH4 $HASH1 -- &&
149 git branch > branch.output &&
150 grep "* other" branch.output > /dev/null
153 test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' '
155 test_must_fail git bisect start $HASH4 foo -- &&
156 git branch > branch.output &&
157 grep "* other" branch.output > /dev/null &&
158 test_path_is_missing .git/BISECT_START
161 test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
162 git bisect start $HASH4 $HASH1 -- &&
164 cp .git/BISECT_START saved &&
165 test_must_fail git bisect start $HASH4 foo -- &&
166 git branch > branch.output &&
167 test_i18ngrep "* (no branch, bisect started on other)" branch.output > /dev/null &&
168 test_cmp saved .git/BISECT_START
170 test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
171 git bisect start $HASH4 $HASH1 -- &&
173 test_must_fail git bisect start $HASH1 $HASH4 -- &&
174 git branch > branch.output &&
175 grep "* other" branch.output > /dev/null &&
176 test_path_is_missing .git/BISECT_START
179 test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
180 echo "temp stuff" > hello &&
181 test_must_fail git bisect start $HASH4 $HASH1 -- &&
183 git branch > branch.output &&
184 grep "* other" branch.output > /dev/null &&
185 test_path_is_missing .git/BISECT_START &&
186 test -z "$(git for-each-ref "refs/bisect/*")" &&
187 git checkout HEAD hello
190 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
192 # so we should find $HASH2 as the first bad commit
193 test_expect_success 'bisect skip: successful result' '
194 test_when_finished git bisect reset &&
196 git bisect start $HASH4 $HASH1 &&
198 git bisect bad > my_bisect_log.txt &&
199 grep "$HASH2 is the first bad commit" my_bisect_log.txt
202 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
203 # so we should not be able to tell the first bad commit
204 # among $HASH2, $HASH3 and $HASH4
205 test_expect_success 'bisect skip: cannot tell between 3 commits' '
206 test_when_finished git bisect reset &&
207 git bisect start $HASH4 $HASH1 &&
209 test_expect_code 2 git bisect skip >my_bisect_log.txt &&
210 grep "first bad commit could be any of" my_bisect_log.txt &&
211 ! grep $HASH1 my_bisect_log.txt &&
212 grep $HASH2 my_bisect_log.txt &&
213 grep $HASH3 my_bisect_log.txt &&
214 grep $HASH4 my_bisect_log.txt
217 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
218 # but $HASH2 is good,
219 # so we should not be able to tell the first bad commit
220 # among $HASH3 and $HASH4
221 test_expect_success 'bisect skip: cannot tell between 2 commits' '
222 test_when_finished git bisect reset &&
223 git bisect start $HASH4 $HASH1 &&
225 test_expect_code 2 git bisect good >my_bisect_log.txt &&
226 grep "first bad commit could be any of" my_bisect_log.txt &&
227 ! grep $HASH1 my_bisect_log.txt &&
228 ! grep $HASH2 my_bisect_log.txt &&
229 grep $HASH3 my_bisect_log.txt &&
230 grep $HASH4 my_bisect_log.txt
233 # $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
234 # and $HASH2 is good,
235 # so we should not be able to tell the first bad commit
236 # among $HASH3 and $HASH4
237 test_expect_success 'bisect skip: with commit both bad and skipped' '
238 test_when_finished git bisect reset &&
242 git bisect good $HASH1 &&
244 test_expect_code 2 git bisect good >my_bisect_log.txt &&
245 grep "first bad commit could be any of" my_bisect_log.txt &&
246 ! grep $HASH1 my_bisect_log.txt &&
247 ! grep $HASH2 my_bisect_log.txt &&
248 grep $HASH3 my_bisect_log.txt &&
249 grep $HASH4 my_bisect_log.txt
252 # We want to automatically find the commit that
253 # added "Another" into hello.
254 test_expect_success '"git bisect run" simple case' '
255 write_script test_script.sh <<-\EOF &&
256 ! grep Another hello >/dev/null
259 git bisect good $HASH1 &&
260 git bisect bad $HASH4 &&
261 git bisect run ./test_script.sh >my_bisect_log.txt &&
262 grep "$HASH3 is the first bad commit" my_bisect_log.txt &&
266 # We want to automatically find the commit that
267 # added "Ciao" into hello.
268 test_expect_success '"git bisect run" with more complex "git bisect start"' '
269 write_script test_script.sh <<-\EOF &&
270 ! grep Ciao hello >/dev/null
272 git bisect start $HASH4 $HASH1 &&
273 git bisect run ./test_script.sh >my_bisect_log.txt &&
274 grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
278 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
279 # but $HASH4 is good,
280 # so we should find $HASH5 as the first bad commit
282 test_expect_success 'bisect skip: add line and then a new test' '
283 add_line_into_file "5: Another new line." hello &&
284 HASH5=$(git rev-parse --verify HEAD) &&
285 git bisect start $HASH5 $HASH1 &&
287 git bisect good > my_bisect_log.txt &&
288 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
289 git bisect log > log_to_replay.txt &&
293 test_expect_success 'bisect skip and bisect replay' '
294 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
295 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
300 test_expect_success 'bisect run & skip: cannot tell between 2' '
301 add_line_into_file "6: Yet a line." hello &&
302 HASH6=$(git rev-parse --verify HEAD) &&
303 write_script test_script.sh <<-\EOF &&
304 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
305 ! grep line hello >/dev/null
307 git bisect start $HASH6 $HASH1 &&
308 test_expect_code 2 git bisect run ./test_script.sh >my_bisect_log.txt &&
309 grep "first bad commit could be any of" my_bisect_log.txt &&
310 ! grep $HASH3 my_bisect_log.txt &&
311 ! grep $HASH6 my_bisect_log.txt &&
312 grep $HASH4 my_bisect_log.txt &&
313 grep $HASH5 my_bisect_log.txt
317 test_expect_success 'bisect run & skip: find first bad' '
319 add_line_into_file "7: Should be the last line." hello &&
320 HASH7=$(git rev-parse --verify HEAD) &&
321 write_script test_script.sh <<-\EOF &&
322 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
323 sed -ne \$p hello | grep day >/dev/null && exit 125
324 ! grep Yet hello >/dev/null
326 git bisect start $HASH7 $HASH1 &&
327 git bisect run ./test_script.sh >my_bisect_log.txt &&
328 grep "$HASH6 is the first bad commit" my_bisect_log.txt
331 test_expect_success 'bisect skip only one range' '
333 git bisect start $HASH7 $HASH1 &&
334 git bisect skip $HASH1..$HASH5 &&
335 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
336 test_must_fail git bisect bad > my_bisect_log.txt &&
337 grep "first bad commit could be any of" my_bisect_log.txt
340 test_expect_success 'bisect skip many ranges' '
341 git bisect start $HASH7 $HASH1 &&
342 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
343 git bisect skip $HASH2 $HASH2.. ..$HASH5 &&
344 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
345 test_must_fail git bisect bad > my_bisect_log.txt &&
346 grep "first bad commit could be any of" my_bisect_log.txt
349 test_expect_success 'bisect starting with a detached HEAD' '
351 git checkout master^ &&
352 HEAD=$(git rev-parse --verify HEAD) &&
354 test $HEAD = $(cat .git/BISECT_START) &&
356 test $HEAD = $(git rev-parse --verify HEAD)
359 test_expect_success 'bisect errors out if bad and good are mistaken' '
361 test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
362 test_i18ngrep "mistook good and bad" rev_list_error &&
366 test_expect_success 'bisect does not create a "bisect" branch' '
368 git bisect start $HASH7 $HASH1 &&
370 rev_hash4=$(git rev-parse --verify HEAD) &&
371 test "$rev_hash4" = "$HASH4" &&
372 git branch -D bisect &&
375 rev_hash6=$(git rev-parse --verify HEAD) &&
376 test "$rev_hash6" = "$HASH6" &&
377 git bisect good > my_bisect_log.txt &&
378 grep "$HASH7 is the first bad commit" my_bisect_log.txt &&
380 rev_hash6=$(git rev-parse --verify bisect) &&
381 test "$rev_hash6" = "$HASH6" &&
385 # This creates a "side" branch to test "siblings" cases.
387 # H1-H2-H3-H4-H5-H6-H7 <--other
391 test_expect_success 'side branch creation' '
393 git checkout -b side $HASH4 &&
394 add_line_into_file "5(side): first line on a side branch" hello2 &&
395 SIDE_HASH5=$(git rev-parse --verify HEAD) &&
396 add_line_into_file "6(side): second line on a side branch" hello2 &&
397 SIDE_HASH6=$(git rev-parse --verify HEAD) &&
398 add_line_into_file "7(side): third line on a side branch" hello2 &&
399 SIDE_HASH7=$(git rev-parse --verify HEAD)
402 test_expect_success 'good merge base when good and bad are siblings' '
403 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
404 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
405 grep $HASH4 my_bisect_log.txt &&
406 git bisect good > my_bisect_log.txt &&
407 ! grep "merge base must be tested" my_bisect_log.txt &&
408 grep $HASH6 my_bisect_log.txt &&
411 test_expect_success 'skipped merge base when good and bad are siblings' '
412 git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt &&
413 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
414 grep $HASH4 my_bisect_log.txt &&
415 git bisect skip > my_bisect_log.txt 2>&1 &&
416 grep "warning" my_bisect_log.txt &&
417 grep $SIDE_HASH6 my_bisect_log.txt &&
421 test_expect_success 'bad merge base when good and bad are siblings' '
422 git bisect start "$HASH7" HEAD > my_bisect_log.txt &&
423 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
424 grep $HASH4 my_bisect_log.txt &&
425 test_must_fail git bisect bad > my_bisect_log.txt 2>&1 &&
426 test_i18ngrep "merge base $HASH4 is bad" my_bisect_log.txt &&
427 test_i18ngrep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt &&
431 # This creates a few more commits (A and B) to test "siblings" cases
432 # when a good and a bad rev have many merge bases.
434 # We should have the following:
436 # H1-H2-H3-H4-H5-H6-H7
442 # And there A and B have 2 merge bases (S5 and H5) that should be
443 # reported by "git merge-base --all A B".
445 test_expect_success 'many merge bases creation' '
446 git checkout "$SIDE_HASH5" &&
447 git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" &&
448 A_HASH=$(git rev-parse --verify HEAD) &&
450 git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" &&
451 B_HASH=$(git rev-parse --verify HEAD) &&
452 git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt &&
453 test_line_count = 2 merge_bases.txt &&
454 grep "$HASH5" merge_bases.txt &&
455 grep "$SIDE_HASH5" merge_bases.txt
458 # We want to automatically find the merge that
459 # added "line" into hello.
460 test_expect_success '"git bisect run --first-parent" simple case' '
461 git rev-list --first-parent $B_HASH ^$HASH4 >first_parent_chain.txt &&
462 write_script test_script.sh <<-\EOF &&
463 grep $(git rev-parse HEAD) first_parent_chain.txt || exit -1
464 ! grep line hello >/dev/null
466 git bisect start --first-parent &&
467 test_path_is_file ".git/BISECT_FIRST_PARENT" &&
468 git bisect good $HASH4 &&
469 git bisect bad $B_HASH &&
470 git bisect run ./test_script.sh >my_bisect_log.txt &&
471 grep "$B_HASH is the first bad commit" my_bisect_log.txt &&
473 test_path_is_missing .git/BISECT_FIRST_PARENT
476 test_expect_success 'good merge bases when good and bad are siblings' '
477 git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt &&
478 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
479 git bisect good > my_bisect_log2.txt &&
480 test_i18ngrep "merge base must be tested" my_bisect_log2.txt &&
483 grep "$SIDE_HASH5" my_bisect_log.txt &&
484 grep "$HASH5" my_bisect_log2.txt
486 grep "$SIDE_HASH5" my_bisect_log2.txt &&
487 grep "$HASH5" my_bisect_log.txt
493 test_expect_success 'optimized merge base checks' '
494 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
495 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
496 grep "$HASH4" my_bisect_log.txt &&
497 git bisect good > my_bisect_log2.txt &&
498 test -f ".git/BISECT_ANCESTORS_OK" &&
499 test "$HASH6" = $(git rev-parse --verify HEAD) &&
501 git bisect good "$A_HASH" > my_bisect_log4.txt &&
502 test_i18ngrep "merge base must be tested" my_bisect_log4.txt &&
503 test_path_is_missing ".git/BISECT_ANCESTORS_OK"
506 # This creates another side branch called "parallel" with some files
507 # in some directories, to test bisecting with paths.
509 # We should have the following:
511 # P1-P2-P3-P4-P5-P6-P7
513 # H1-H2-H3-H4-H5-H6-H7
519 test_expect_success '"parallel" side branch creation' '
521 git checkout -b parallel $HASH1 &&
523 add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 &&
524 PARA_HASH1=$(git rev-parse --verify HEAD) &&
525 add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
526 PARA_HASH2=$(git rev-parse --verify HEAD) &&
527 add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
528 PARA_HASH3=$(git rev-parse --verify HEAD) &&
529 git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
530 PARA_HASH4=$(git rev-parse --verify HEAD) &&
531 add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
532 PARA_HASH5=$(git rev-parse --verify HEAD) &&
533 add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
534 PARA_HASH6=$(git rev-parse --verify HEAD) &&
535 git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
536 PARA_HASH7=$(git rev-parse --verify HEAD)
539 test_expect_success 'restricting bisection on one dir' '
541 git bisect start HEAD $HASH1 -- dir1 &&
542 para1=$(git rev-parse --verify HEAD) &&
543 test "$para1" = "$PARA_HASH1" &&
544 git bisect bad > my_bisect_log.txt &&
545 grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
548 test_expect_success 'restricting bisection on one dir and a file' '
550 git bisect start HEAD $HASH1 -- dir1 hello &&
551 para4=$(git rev-parse --verify HEAD) &&
552 test "$para4" = "$PARA_HASH4" &&
554 hash3=$(git rev-parse --verify HEAD) &&
555 test "$hash3" = "$HASH3" &&
557 hash4=$(git rev-parse --verify HEAD) &&
558 test "$hash4" = "$HASH4" &&
560 para1=$(git rev-parse --verify HEAD) &&
561 test "$para1" = "$PARA_HASH1" &&
562 git bisect good > my_bisect_log.txt &&
563 grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
566 test_expect_success 'skipping away from skipped commit' '
567 git bisect start $PARA_HASH7 $HASH1 &&
568 para4=$(git rev-parse --verify HEAD) &&
569 test "$para4" = "$PARA_HASH4" &&
571 hash7=$(git rev-parse --verify HEAD) &&
572 test "$hash7" = "$HASH7" &&
574 para3=$(git rev-parse --verify HEAD) &&
575 test "$para3" = "$PARA_HASH3"
578 test_expect_success 'erroring out when using bad path parameters' '
579 test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
580 test_i18ngrep "bad path parameters" error.txt
583 test_expect_success 'test bisection on bare repo - --no-checkout specified' '
584 git clone --bare . bare.nocheckout &&
586 cd bare.nocheckout &&
587 git bisect start --no-checkout &&
588 git bisect good $HASH1 &&
589 git bisect bad $HASH4 &&
590 git bisect run eval \
591 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
594 grep "$HASH3 is the first bad commit" nocheckout.log
598 test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
599 git clone --bare . bare.defaulted &&
603 git bisect good $HASH1 &&
604 git bisect bad $HASH4 &&
605 git bisect run eval \
606 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
609 grep "$HASH3 is the first bad commit" defaulted.log
613 # This creates a broken branch which cannot be checked out because
614 # the tree created has been deleted.
616 # H1-H2-H3-H4-H5-H6-H7 <--other
618 # S5-S6'-S7'-S8'-S9 <--broken
620 # Commits marked with ' have a missing tree.
622 test_expect_success 'broken branch creation' '
624 git checkout -b broken $HASH4 &&
625 git tag BROKEN_HASH4 $HASH4 &&
626 add_line_into_file "5(broken): first line on a broken branch" hello2 &&
627 git tag BROKEN_HASH5 &&
629 :> missing/MISSING &&
630 git add missing/MISSING &&
631 git commit -m "6(broken): Added file that will be deleted" &&
632 git tag BROKEN_HASH6 &&
633 deleted=$(git rev-parse --verify HEAD:missing) &&
634 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
635 git tag BROKEN_HASH7 &&
636 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
637 git tag BROKEN_HASH8 &&
638 git rm missing/MISSING &&
639 git commit -m "9(broken): Remove missing file" &&
640 git tag BROKEN_HASH9 &&
641 rm .git/objects/$(test_oid_to_path $deleted)
644 echo "" > expected.ok
645 cat > expected.missing-tree.default <<EOF
646 fatal: unable to read tree $deleted
649 test_expect_success 'bisect fails if tree is broken on start commit' '
651 test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
652 test_cmp expected.missing-tree.default error.txt
655 test_expect_success 'bisect fails if tree is broken on trial commit' '
657 test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
658 git reset --hard broken &&
659 git checkout broken &&
660 test_cmp expected.missing-tree.default error.txt
665 echo "Checking $1 is the same as $2" &&
666 test_cmp_rev "$1" "$2"
669 test_expect_success 'bisect: --no-checkout - start commit bad' '
671 git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
672 check_same BROKEN_HASH6 BISECT_HEAD &&
676 test_expect_success 'bisect: --no-checkout - trial commit bad' '
678 git bisect start broken BROKEN_HASH4 --no-checkout &&
679 check_same BROKEN_HASH6 BISECT_HEAD &&
683 test_expect_success 'bisect: --no-checkout - target before breakage' '
685 git bisect start broken BROKEN_HASH4 --no-checkout &&
686 check_same BROKEN_HASH6 BISECT_HEAD &&
687 git bisect bad BISECT_HEAD &&
688 check_same BROKEN_HASH5 BISECT_HEAD &&
689 git bisect bad BISECT_HEAD &&
690 check_same BROKEN_HASH5 bisect/bad &&
694 test_expect_success 'bisect: --no-checkout - target in breakage' '
696 git bisect start broken BROKEN_HASH4 --no-checkout &&
697 check_same BROKEN_HASH6 BISECT_HEAD &&
698 git bisect bad BISECT_HEAD &&
699 check_same BROKEN_HASH5 BISECT_HEAD &&
700 test_must_fail git bisect good BISECT_HEAD &&
701 check_same BROKEN_HASH6 bisect/bad &&
705 test_expect_success 'bisect: --no-checkout - target after breakage' '
707 git bisect start broken BROKEN_HASH4 --no-checkout &&
708 check_same BROKEN_HASH6 BISECT_HEAD &&
709 git bisect good BISECT_HEAD &&
710 check_same BROKEN_HASH8 BISECT_HEAD &&
711 test_must_fail git bisect good BISECT_HEAD &&
712 check_same BROKEN_HASH9 bisect/bad &&
716 test_expect_success 'bisect: demonstrate identification of damage boundary' "
718 git checkout broken &&
719 git bisect start broken master --no-checkout &&
720 test_must_fail git bisect run \"\$SHELL_PATH\" -c '
721 GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
722 git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
723 git pack-objects --stdout >/dev/null < tmp.\$\$
727 check_same BROKEN_HASH6 bisect/bad &&
731 cat > expected.bisect-log <<EOF
732 # bad: [$HASH4] Add <4: Ciao for now> into <hello>.
733 # good: [$HASH2] Add <2: A new day for git> into <hello>.
734 git bisect start '$HASH4' '$HASH2'
735 # good: [$HASH3] Add <3: Another new day for git> into <hello>.
736 git bisect good $HASH3
737 # first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
740 test_expect_success 'bisect log: successful result' '
742 git bisect start $HASH4 $HASH2 &&
744 git bisect log >bisect-log.txt &&
745 test_cmp expected.bisect-log bisect-log.txt &&
749 cat > expected.bisect-skip-log <<EOF
750 # bad: [$HASH4] Add <4: Ciao for now> into <hello>.
751 # good: [$HASH2] Add <2: A new day for git> into <hello>.
752 git bisect start '$HASH4' '$HASH2'
753 # skip: [$HASH3] Add <3: Another new day for git> into <hello>.
754 git bisect skip $HASH3
755 # only skipped commits left to test
756 # possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
757 # possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>.
760 test_expect_success 'bisect log: only skip commits left' '
762 git bisect start $HASH4 $HASH2 &&
763 test_must_fail git bisect skip &&
764 git bisect log >bisect-skip-log.txt &&
765 test_cmp expected.bisect-skip-log bisect-skip-log.txt &&
769 test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' '
770 git checkout parallel &&
771 git bisect start HEAD $HASH1 &&
772 git bisect good HEAD &&
773 git bisect bad HEAD &&
774 test "$HASH6" = $(git rev-parse --verify HEAD) &&
778 test_expect_success 'bisect starts with only one new' '
781 git bisect new $HASH4 &&
785 test_expect_success 'bisect does not start with only one old' '
788 git bisect old $HASH1 &&
789 test_must_fail git bisect next
792 test_expect_success 'bisect start with one new and old' '
795 git bisect old $HASH1 &&
796 git bisect new $HASH4 &&
798 git bisect new >bisect_result &&
799 grep "$HASH2 is the first new commit" bisect_result &&
800 git bisect log >log_to_replay.txt &&
804 test_expect_success 'bisect replay with old and new' '
805 git bisect replay log_to_replay.txt >bisect_result &&
806 grep "$HASH2 is the first new commit" bisect_result &&
810 test_expect_success 'bisect replay with CRLF log' '
811 append_cr <log_to_replay.txt >log_to_replay_crlf.txt &&
812 git bisect replay log_to_replay_crlf.txt >bisect_result_crlf &&
813 grep "$HASH2 is the first new commit" bisect_result_crlf &&
817 test_expect_success 'bisect cannot mix old/new and good/bad' '
819 git bisect bad $HASH4 &&
820 test_must_fail git bisect old $HASH1
823 test_expect_success 'bisect terms needs 0 or 1 argument' '
825 test_must_fail git bisect terms only-one &&
826 test_must_fail git bisect terms 1 2 &&
827 test_must_fail git bisect terms 2>actual &&
828 echo "error: no terms defined" >expected &&
829 test_i18ncmp expected actual
832 test_expect_success 'bisect terms shows good/bad after start' '
834 git bisect start HEAD $HASH1 &&
835 git bisect terms --term-good >actual &&
836 echo good >expected &&
837 test_cmp expected actual &&
838 git bisect terms --term-bad >actual &&
839 echo bad >expected &&
840 test_cmp expected actual
843 test_expect_success 'bisect start with one term1 and term2' '
845 git bisect start --term-old term2 --term-new term1 &&
846 git bisect term2 $HASH1 &&
847 git bisect term1 $HASH4 &&
849 git bisect term1 >bisect_result &&
850 grep "$HASH2 is the first term1 commit" bisect_result &&
851 git bisect log >log_to_replay.txt &&
855 test_expect_success 'bisect replay with term1 and term2' '
856 git bisect replay log_to_replay.txt >bisect_result &&
857 grep "$HASH2 is the first term1 commit" bisect_result &&
861 test_expect_success 'bisect start term1 term2' '
863 git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
865 git bisect term1 >bisect_result &&
866 grep "$HASH2 is the first term1 commit" bisect_result &&
867 git bisect log >log_to_replay.txt &&
871 test_expect_success 'bisect cannot mix terms' '
873 git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 &&
874 test_must_fail git bisect a &&
875 test_must_fail git bisect b &&
876 test_must_fail git bisect bad &&
877 test_must_fail git bisect good &&
878 test_must_fail git bisect new &&
879 test_must_fail git bisect old
882 test_expect_success 'bisect terms rejects invalid terms' '
884 test_must_fail git bisect start --term-good &&
885 test_must_fail git bisect start --term-good invalid..term &&
886 test_must_fail git bisect start --term-bad &&
887 test_must_fail git bisect terms --term-bad invalid..term &&
888 test_must_fail git bisect terms --term-good bad &&
889 test_must_fail git bisect terms --term-good old &&
890 test_must_fail git bisect terms --term-good skip &&
891 test_must_fail git bisect terms --term-good reset &&
892 test_path_is_missing .git/BISECT_TERMS
895 test_expect_success 'bisect start --term-* does store terms' '
897 git bisect start --term-bad=one --term-good=two &&
898 git bisect terms >actual &&
899 cat <<-EOF >expected &&
900 Your current terms are two for the old state
901 and one for the new state.
903 test_i18ncmp expected actual &&
904 git bisect terms --term-bad >actual &&
905 echo one >expected &&
906 test_cmp expected actual &&
907 git bisect terms --term-good >actual &&
908 echo two >expected &&
909 test_cmp expected actual
912 test_expect_success 'bisect start takes options and revs in any order' '
914 git bisect start --term-good one $HASH4 \
915 --term-good two --term-bad bad-term \
916 $HASH1 --term-good three -- &&
917 (git bisect terms --term-bad && git bisect terms --term-good) >actual &&
918 printf "%s\n%s\n" bad-term three >expected &&
919 test_cmp expected actual
922 test_expect_success 'git bisect reset cleans bisection state properly' '
925 git bisect good $HASH1 &&
926 git bisect bad $HASH4 &&
928 test -z "$(git for-each-ref "refs/bisect/*")" &&
929 test_path_is_missing "$GIT_DIR/BISECT_EXPECTED_REV" &&
930 test_path_is_missing "$GIT_DIR/BISECT_ANCESTORS_OK" &&
931 test_path_is_missing "$GIT_DIR/BISECT_LOG" &&
932 test_path_is_missing "$GIT_DIR/BISECT_RUN" &&
933 test_path_is_missing "$GIT_DIR/BISECT_TERMS" &&
934 test_path_is_missing "$GIT_DIR/head-name" &&
935 test_path_is_missing "$GIT_DIR/BISECT_HEAD" &&
936 test_path_is_missing "$GIT_DIR/BISECT_START"