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 reset: back in the master branch' '
87 echo "* master" > branch.expect &&
88 git branch > branch.output &&
89 cmp branch.expect branch.output
92 test_expect_success
'bisect reset: back in another branch' '
93 git checkout -b other &&
95 git bisect good $HASH1 &&
96 git bisect bad $HASH3 &&
98 echo " master" > branch.expect &&
99 echo "* other" >> branch.expect &&
100 git branch > branch.output &&
101 cmp branch.expect branch.output
104 test_expect_success
'bisect reset when not bisecting' '
106 git branch > branch.output &&
107 cmp branch.expect branch.output
110 test_expect_success
'bisect reset removes packed refs' '
113 git bisect good $HASH1 &&
114 git bisect bad $HASH3 &&
115 git pack-refs --all --prune &&
118 test -z "$(git for-each-ref "refs/bisect/*")" &&
119 test -z "$(git for-each-ref "refs/heads/bisect")"
122 test_expect_success
'bisect reset removes bisect state after --no-checkout' '
124 git bisect start --no-checkout &&
125 git bisect good $HASH1 &&
126 git bisect bad $HASH3 &&
129 test -z "$(git for-each-ref "refs/bisect/*")" &&
130 test -z "$(git for-each-ref "refs/heads/bisect")" &&
131 test -z "$(git for-each-ref "BISECT_HEAD")"
134 test_expect_success
'bisect start: back in good branch' '
135 git branch > branch.output &&
136 grep "* other" branch.output > /dev/null &&
137 git bisect start $HASH4 $HASH1 -- &&
139 git bisect start $HASH4 $HASH1 -- &&
142 git branch > branch.output &&
143 grep "* other" branch.output > /dev/null
146 test_expect_success
'bisect start: no ".git/BISECT_START" created if junk rev' '
148 test_must_fail git bisect start $HASH4 foo -- &&
149 git branch > branch.output &&
150 grep "* other" branch.output > /dev/null &&
151 test_must_fail test -e .git/BISECT_START
154 test_expect_success
'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
155 git bisect start $HASH4 $HASH1 -- &&
157 cp .git/BISECT_START saved &&
158 test_must_fail git bisect start $HASH4 foo -- &&
159 git branch > branch.output &&
160 test_i18ngrep "* (no branch, bisect started on other)" branch.output > /dev/null &&
161 test_cmp saved .git/BISECT_START
163 test_expect_success
'bisect start: no ".git/BISECT_START" if mistaken rev' '
164 git bisect start $HASH4 $HASH1 -- &&
166 test_must_fail git bisect start $HASH1 $HASH4 -- &&
167 git branch > branch.output &&
168 grep "* other" branch.output > /dev/null &&
169 test_must_fail test -e .git/BISECT_START
172 test_expect_success
'bisect start: no ".git/BISECT_START" if checkout error' '
173 echo "temp stuff" > hello &&
174 test_must_fail git bisect start $HASH4 $HASH1 -- &&
176 git branch > branch.output &&
177 grep "* other" branch.output > /dev/null &&
178 test_must_fail test -e .git/BISECT_START &&
179 test -z "$(git for-each-ref "refs/bisect/*")" &&
180 git checkout HEAD hello
183 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
185 # so we should find $HASH2 as the first bad commit
186 test_expect_success
'bisect skip: successful result' '
187 test_when_finished git bisect reset &&
189 git bisect start $HASH4 $HASH1 &&
191 git bisect bad > my_bisect_log.txt &&
192 grep "$HASH2 is the first bad commit" my_bisect_log.txt
195 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
196 # so we should not be able to tell the first bad commit
197 # among $HASH2, $HASH3 and $HASH4
198 test_expect_success
'bisect skip: cannot tell between 3 commits' '
199 test_when_finished git bisect reset &&
200 git bisect start $HASH4 $HASH1 &&
202 test_expect_code 2 git bisect skip >my_bisect_log.txt &&
203 grep "first bad commit could be any of" my_bisect_log.txt &&
204 ! grep $HASH1 my_bisect_log.txt &&
205 grep $HASH2 my_bisect_log.txt &&
206 grep $HASH3 my_bisect_log.txt &&
207 grep $HASH4 my_bisect_log.txt
210 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
211 # but $HASH2 is good,
212 # so we should not be able to tell the first bad commit
213 # among $HASH3 and $HASH4
214 test_expect_success
'bisect skip: cannot tell between 2 commits' '
215 test_when_finished git bisect reset &&
216 git bisect start $HASH4 $HASH1 &&
218 test_expect_code 2 git bisect good >my_bisect_log.txt &&
219 grep "first bad commit could be any of" my_bisect_log.txt &&
220 ! grep $HASH1 my_bisect_log.txt &&
221 ! grep $HASH2 my_bisect_log.txt &&
222 grep $HASH3 my_bisect_log.txt &&
223 grep $HASH4 my_bisect_log.txt
226 # $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
227 # and $HASH2 is good,
228 # so we should not be able to tell the first bad commit
229 # among $HASH3 and $HASH4
230 test_expect_success
'bisect skip: with commit both bad and skipped' '
231 test_when_finished git bisect reset &&
235 git bisect good $HASH1 &&
237 test_expect_code 2 git bisect good >my_bisect_log.txt &&
238 grep "first bad commit could be any of" my_bisect_log.txt &&
239 ! grep $HASH1 my_bisect_log.txt &&
240 ! grep $HASH2 my_bisect_log.txt &&
241 grep $HASH3 my_bisect_log.txt &&
242 grep $HASH4 my_bisect_log.txt
245 # We want to automatically find the commit that
246 # introduced "Another" into hello.
247 test_expect_success \
248 '"git bisect run" simple case' \
249 'echo "#"\!"/bin/sh" > test_script.sh &&
250 echo "grep Another hello > /dev/null" >> test_script.sh &&
251 echo "test \$? -ne 0" >> test_script.sh &&
252 chmod +x test_script.sh &&
254 git bisect good $HASH1 &&
255 git bisect bad $HASH4 &&
256 git bisect run ./test_script.sh > my_bisect_log.txt &&
257 grep "$HASH3 is the first bad commit" my_bisect_log.txt &&
260 # We want to automatically find the commit that
261 # introduced "Ciao" into hello.
262 test_expect_success \
263 '"git bisect run" with more complex "git bisect start"' \
264 'echo "#"\!"/bin/sh" > test_script.sh &&
265 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
266 echo "test \$? -ne 0" >> test_script.sh &&
267 chmod +x test_script.sh &&
268 git bisect start $HASH4 $HASH1 &&
269 git bisect run ./test_script.sh > my_bisect_log.txt &&
270 grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
273 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
274 # but $HASH4 is good,
275 # so we should find $HASH5 as the first bad commit
277 test_expect_success
'bisect skip: add line and then a new test' '
278 add_line_into_file "5: Another new line." hello &&
279 HASH5=$(git rev-parse --verify HEAD) &&
280 git bisect start $HASH5 $HASH1 &&
282 git bisect good > my_bisect_log.txt &&
283 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
284 git bisect log > log_to_replay.txt &&
288 test_expect_success
'bisect skip and bisect replay' '
289 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
290 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
295 test_expect_success
'bisect run & skip: cannot tell between 2' '
296 add_line_into_file "6: Yet a line." hello &&
297 HASH6=$(git rev-parse --verify HEAD) &&
298 echo "#"\!"/bin/sh" > test_script.sh &&
299 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
300 echo "grep line hello > /dev/null" >> test_script.sh &&
301 echo "test \$? -ne 0" >> test_script.sh &&
302 chmod +x test_script.sh &&
303 git bisect start $HASH6 $HASH1 &&
304 if git bisect run ./test_script.sh > my_bisect_log.txt
306 echo Oops, should have failed.
310 grep "first bad commit could be any of" my_bisect_log.txt &&
311 ! grep $HASH3 my_bisect_log.txt &&
312 ! grep $HASH6 my_bisect_log.txt &&
313 grep $HASH4 my_bisect_log.txt &&
314 grep $HASH5 my_bisect_log.txt
319 test_expect_success
'bisect run & skip: find first bad' '
321 add_line_into_file "7: Should be the last line." hello &&
322 HASH7=$(git rev-parse --verify HEAD) &&
323 echo "#"\!"/bin/sh" > test_script.sh &&
324 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
325 echo "sed -ne \\\$p hello | grep day > /dev/null && exit 125" >> test_script.sh &&
326 echo "grep Yet hello > /dev/null" >> test_script.sh &&
327 echo "test \$? -ne 0" >> test_script.sh &&
328 chmod +x test_script.sh &&
329 git bisect start $HASH7 $HASH1 &&
330 git bisect run ./test_script.sh > my_bisect_log.txt &&
331 grep "$HASH6 is the first bad commit" my_bisect_log.txt
334 test_expect_success
'bisect skip only one range' '
336 git bisect start $HASH7 $HASH1 &&
337 git bisect skip $HASH1..$HASH5 &&
338 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
339 test_must_fail git bisect bad > my_bisect_log.txt &&
340 grep "first bad commit could be any of" my_bisect_log.txt
343 test_expect_success
'bisect skip many ranges' '
344 git bisect start $HASH7 $HASH1 &&
345 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
346 git bisect skip $HASH2 $HASH2.. ..$HASH5 &&
347 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
348 test_must_fail git bisect bad > my_bisect_log.txt &&
349 grep "first bad commit could be any of" my_bisect_log.txt
352 test_expect_success
'bisect starting with a detached HEAD' '
354 git checkout master^ &&
355 HEAD=$(git rev-parse --verify HEAD) &&
357 test $HEAD = $(cat .git/BISECT_START) &&
359 test $HEAD = $(git rev-parse --verify HEAD)
362 test_expect_success
'bisect errors out if bad and good are mistaken' '
364 test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
365 test_i18ngrep "mistook good and bad" rev_list_error &&
369 test_expect_success
'bisect does not create a "bisect" branch' '
371 git bisect start $HASH7 $HASH1 &&
373 rev_hash4=$(git rev-parse --verify HEAD) &&
374 test "$rev_hash4" = "$HASH4" &&
375 git branch -D bisect &&
378 rev_hash6=$(git rev-parse --verify HEAD) &&
379 test "$rev_hash6" = "$HASH6" &&
380 git bisect good > my_bisect_log.txt &&
381 grep "$HASH7 is the first bad commit" my_bisect_log.txt &&
383 rev_hash6=$(git rev-parse --verify bisect) &&
384 test "$rev_hash6" = "$HASH6" &&
388 # This creates a "side" branch to test "siblings" cases.
390 # H1-H2-H3-H4-H5-H6-H7 <--other
394 test_expect_success
'side branch creation' '
396 git checkout -b side $HASH4 &&
397 add_line_into_file "5(side): first line on a side branch" hello2 &&
398 SIDE_HASH5=$(git rev-parse --verify HEAD) &&
399 add_line_into_file "6(side): second line on a side branch" hello2 &&
400 SIDE_HASH6=$(git rev-parse --verify HEAD) &&
401 add_line_into_file "7(side): third line on a side branch" hello2 &&
402 SIDE_HASH7=$(git rev-parse --verify HEAD)
405 test_expect_success
'good merge base when good and bad are siblings' '
406 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
407 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
408 grep $HASH4 my_bisect_log.txt &&
409 git bisect good > my_bisect_log.txt &&
410 ! grep "merge base must be tested" my_bisect_log.txt &&
411 grep $HASH6 my_bisect_log.txt &&
414 test_expect_success
'skipped merge base when good and bad are siblings' '
415 git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt &&
416 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
417 grep $HASH4 my_bisect_log.txt &&
418 git bisect skip > my_bisect_log.txt 2>&1 &&
419 grep "warning" my_bisect_log.txt &&
420 grep $SIDE_HASH6 my_bisect_log.txt &&
424 test_expect_success
'bad merge base when good and bad are siblings' '
425 git bisect start "$HASH7" HEAD > my_bisect_log.txt &&
426 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
427 grep $HASH4 my_bisect_log.txt &&
428 test_must_fail git bisect bad > my_bisect_log.txt 2>&1 &&
429 test_i18ngrep "merge base $HASH4 is bad" my_bisect_log.txt &&
430 test_i18ngrep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt &&
434 # This creates a few more commits (A and B) to test "siblings" cases
435 # when a good and a bad rev have many merge bases.
437 # We should have the following:
439 # H1-H2-H3-H4-H5-H6-H7
445 # And there A and B have 2 merge bases (S5 and H5) that should be
446 # reported by "git merge-base --all A B".
448 test_expect_success
'many merge bases creation' '
449 git checkout "$SIDE_HASH5" &&
450 git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" &&
451 A_HASH=$(git rev-parse --verify HEAD) &&
453 git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" &&
454 B_HASH=$(git rev-parse --verify HEAD) &&
455 git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt &&
456 test_line_count = 2 merge_bases.txt &&
457 grep "$HASH5" merge_bases.txt &&
458 grep "$SIDE_HASH5" merge_bases.txt
461 test_expect_success
'good merge bases when good and bad are siblings' '
462 git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt &&
463 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
464 git bisect good > my_bisect_log2.txt &&
465 test_i18ngrep "merge base must be tested" my_bisect_log2.txt &&
468 grep "$SIDE_HASH5" my_bisect_log.txt &&
469 grep "$HASH5" my_bisect_log2.txt
471 grep "$SIDE_HASH5" my_bisect_log2.txt &&
472 grep "$HASH5" my_bisect_log.txt
478 test_expect_success
'optimized merge base checks' '
479 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
480 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
481 grep "$HASH4" my_bisect_log.txt &&
482 git bisect good > my_bisect_log2.txt &&
483 test -f ".git/BISECT_ANCESTORS_OK" &&
484 test "$HASH6" = $(git rev-parse --verify HEAD) &&
485 git bisect bad > my_bisect_log3.txt &&
486 git bisect good "$A_HASH" > my_bisect_log4.txt &&
487 test_i18ngrep "merge base must be tested" my_bisect_log4.txt &&
488 test_must_fail test -f ".git/BISECT_ANCESTORS_OK"
491 # This creates another side branch called "parallel" with some files
492 # in some directories, to test bisecting with paths.
494 # We should have the following:
496 # P1-P2-P3-P4-P5-P6-P7
498 # H1-H2-H3-H4-H5-H6-H7
504 test_expect_success
'"parallel" side branch creation' '
506 git checkout -b parallel $HASH1 &&
508 add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 &&
509 PARA_HASH1=$(git rev-parse --verify HEAD) &&
510 add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
511 PARA_HASH2=$(git rev-parse --verify HEAD) &&
512 add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
513 PARA_HASH3=$(git rev-parse --verify HEAD) &&
514 git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
515 PARA_HASH4=$(git rev-parse --verify HEAD) &&
516 add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
517 PARA_HASH5=$(git rev-parse --verify HEAD) &&
518 add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
519 PARA_HASH6=$(git rev-parse --verify HEAD) &&
520 git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
521 PARA_HASH7=$(git rev-parse --verify HEAD)
524 test_expect_success
'restricting bisection on one dir' '
526 git bisect start HEAD $HASH1 -- dir1 &&
527 para1=$(git rev-parse --verify HEAD) &&
528 test "$para1" = "$PARA_HASH1" &&
529 git bisect bad > my_bisect_log.txt &&
530 grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
533 test_expect_success
'restricting bisection on one dir and a file' '
535 git bisect start HEAD $HASH1 -- dir1 hello &&
536 para4=$(git rev-parse --verify HEAD) &&
537 test "$para4" = "$PARA_HASH4" &&
539 hash3=$(git rev-parse --verify HEAD) &&
540 test "$hash3" = "$HASH3" &&
542 hash4=$(git rev-parse --verify HEAD) &&
543 test "$hash4" = "$HASH4" &&
545 para1=$(git rev-parse --verify HEAD) &&
546 test "$para1" = "$PARA_HASH1" &&
547 git bisect good > my_bisect_log.txt &&
548 grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
551 test_expect_success
'skipping away from skipped commit' '
552 git bisect start $PARA_HASH7 $HASH1 &&
553 para4=$(git rev-parse --verify HEAD) &&
554 test "$para4" = "$PARA_HASH4" &&
556 hash7=$(git rev-parse --verify HEAD) &&
557 test "$hash7" = "$HASH7" &&
559 para3=$(git rev-parse --verify HEAD) &&
560 test "$para3" = "$PARA_HASH3"
563 test_expect_success
'erroring out when using bad path parameters' '
564 test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
565 test_i18ngrep "bad path parameters" error.txt
568 test_expect_success
'test bisection on bare repo - --no-checkout specified' '
569 git clone --bare . bare.nocheckout &&
571 cd bare.nocheckout &&
572 git bisect start --no-checkout &&
573 git bisect good $HASH1 &&
574 git bisect bad $HASH4 &&
575 git bisect run eval \
576 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
579 grep "$HASH3 is the first bad commit" nocheckout.log
583 test_expect_success
'test bisection on bare repo - --no-checkout defaulted' '
584 git clone --bare . bare.defaulted &&
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" defaulted.log
598 # This creates a broken branch which cannot be checked out because
599 # the tree created has been deleted.
601 # H1-H2-H3-H4-H5-H6-H7 <--other
603 # S5-S6'-S7'-S8'-S9 <--broken
605 # Commits marked with ' have a missing tree.
607 test_expect_success
'broken branch creation' '
609 git checkout -b broken $HASH4 &&
610 git tag BROKEN_HASH4 $HASH4 &&
611 add_line_into_file "5(broken): first line on a broken branch" hello2 &&
612 git tag BROKEN_HASH5 &&
614 :> missing/MISSING &&
615 git add missing/MISSING &&
616 git commit -m "6(broken): Added file that will be deleted" &&
617 git tag BROKEN_HASH6 &&
618 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
619 git tag BROKEN_HASH7 &&
620 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
621 git tag BROKEN_HASH8 &&
622 git rm missing/MISSING &&
623 git commit -m "9(broken): Remove missing file" &&
624 git tag BROKEN_HASH9 &&
625 rm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d
628 echo "" > expected.ok
629 cat > expected.missing-tree.default
<<EOF
630 fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d
633 test_expect_success
'bisect fails if tree is broken on start commit' '
635 test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
636 test_cmp expected.missing-tree.default error.txt
639 test_expect_success
'bisect fails if tree is broken on trial commit' '
641 test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
642 git reset --hard broken &&
643 git checkout broken &&
644 test_cmp expected.missing-tree.default error.txt
649 echo "Checking $1 is the same as $2" &&
650 test_cmp_rev
"$1" "$2"
653 test_expect_success
'bisect: --no-checkout - start commit bad' '
655 git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
656 check_same BROKEN_HASH6 BISECT_HEAD &&
660 test_expect_success
'bisect: --no-checkout - trial commit bad' '
662 git bisect start broken BROKEN_HASH4 --no-checkout &&
663 check_same BROKEN_HASH6 BISECT_HEAD &&
667 test_expect_success
'bisect: --no-checkout - target before breakage' '
669 git bisect start broken BROKEN_HASH4 --no-checkout &&
670 check_same BROKEN_HASH6 BISECT_HEAD &&
671 git bisect bad BISECT_HEAD &&
672 check_same BROKEN_HASH5 BISECT_HEAD &&
673 git bisect bad BISECT_HEAD &&
674 check_same BROKEN_HASH5 bisect/bad &&
678 test_expect_success
'bisect: --no-checkout - target in breakage' '
680 git bisect start broken BROKEN_HASH4 --no-checkout &&
681 check_same BROKEN_HASH6 BISECT_HEAD &&
682 git bisect bad BISECT_HEAD &&
683 check_same BROKEN_HASH5 BISECT_HEAD &&
684 git bisect good BISECT_HEAD &&
685 check_same BROKEN_HASH6 bisect/bad &&
689 test_expect_success
'bisect: --no-checkout - target after breakage' '
691 git bisect start broken BROKEN_HASH4 --no-checkout &&
692 check_same BROKEN_HASH6 BISECT_HEAD &&
693 git bisect good BISECT_HEAD &&
694 check_same BROKEN_HASH8 BISECT_HEAD &&
695 git bisect good BISECT_HEAD &&
696 check_same BROKEN_HASH9 bisect/bad &&
700 test_expect_success
'bisect: demonstrate identification of damage boundary' "
702 git checkout broken &&
703 git bisect start broken master --no-checkout &&
704 git bisect run \"\$SHELL_PATH\" -c '
705 GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
706 git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
707 git pack-objects --stdout >/dev/null < tmp.\$\$
711 check_same BROKEN_HASH6 bisect/bad &&
715 cat > expected.bisect-log
<<EOF
716 # bad: [32a594a3fdac2d57cf6d02987e30eec68511498c] Add <4: Ciao for now> into <hello>.
717 # good: [7b7f204a749c3125d5224ed61ea2ae1187ad046f] Add <2: A new day for git> into <hello>.
718 git bisect start '32a594a3fdac2d57cf6d02987e30eec68511498c' '7b7f204a749c3125d5224ed61ea2ae1187ad046f'
719 # good: [3de952f2416b6084f557ec417709eac740c6818c] Add <3: Another new day for git> into <hello>.
720 git bisect good 3de952f2416b6084f557ec417709eac740c6818c
721 # first bad commit: [32a594a3fdac2d57cf6d02987e30eec68511498c] Add <4: Ciao for now> into <hello>.
724 test_expect_success
'bisect log: successful result' '
726 git bisect start $HASH4 $HASH2 &&
728 git bisect log >bisect-log.txt &&
729 test_cmp expected.bisect-log bisect-log.txt &&
733 cat > expected.bisect-skip-log
<<EOF
734 # bad: [32a594a3fdac2d57cf6d02987e30eec68511498c] Add <4: Ciao for now> into <hello>.
735 # good: [7b7f204a749c3125d5224ed61ea2ae1187ad046f] Add <2: A new day for git> into <hello>.
736 git bisect start '32a594a3fdac2d57cf6d02987e30eec68511498c' '7b7f204a749c3125d5224ed61ea2ae1187ad046f'
737 # skip: [3de952f2416b6084f557ec417709eac740c6818c] Add <3: Another new day for git> into <hello>.
738 git bisect skip 3de952f2416b6084f557ec417709eac740c6818c
739 # only skipped commits left to test
740 # possible first bad commit: [32a594a3fdac2d57cf6d02987e30eec68511498c] Add <4: Ciao for now> into <hello>.
741 # possible first bad commit: [3de952f2416b6084f557ec417709eac740c6818c] Add <3: Another new day for git> into <hello>.
744 test_expect_success
'bisect log: only skip commits left' '
746 git bisect start $HASH4 $HASH2 &&
747 test_must_fail git bisect skip &&
748 git bisect log >bisect-skip-log.txt &&
749 test_cmp expected.bisect-skip-log bisect-skip-log.txt &&
753 test_expect_success
'"git bisect bad HEAD" behaves as "git bisect bad"' '
754 git checkout parallel &&
755 git bisect start HEAD $HASH1 &&
756 git bisect good HEAD &&
757 git bisect bad HEAD &&
758 test "$HASH6" = $(git rev-parse --verify HEAD) &&
762 test_expect_success
'bisect starts with only one new' '
765 git bisect new $HASH4 &&
769 test_expect_success
'bisect does not start with only one old' '
772 git bisect old $HASH1 &&
773 test_must_fail git bisect next
776 test_expect_success
'bisect start with one new and old' '
779 git bisect old $HASH1 &&
780 git bisect new $HASH4 &&
782 git bisect new >bisect_result &&
783 grep "$HASH2 is the first new commit" bisect_result &&
784 git bisect log >log_to_replay.txt &&
788 test_expect_success
'bisect replay with old and new' '
789 git bisect replay log_to_replay.txt >bisect_result &&
790 grep "$HASH2 is the first new commit" bisect_result &&
794 test_expect_success
'bisect cannot mix old/new and good/bad' '
796 git bisect bad $HASH4 &&
797 test_must_fail git bisect old $HASH1
800 test_expect_success
'bisect terms needs 0 or 1 argument' '
802 test_must_fail git bisect terms only-one &&
803 test_must_fail git bisect terms 1 2 &&
804 test_must_fail git bisect terms 2>actual &&
805 echo "no terms defined" >expected &&
806 test_i18ncmp expected actual
809 test_expect_success
'bisect terms shows good/bad after start' '
811 git bisect start HEAD $HASH1 &&
812 git bisect terms --term-good >actual &&
813 echo good >expected &&
814 test_cmp expected actual &&
815 git bisect terms --term-bad >actual &&
816 echo bad >expected &&
817 test_cmp expected actual
820 test_expect_success
'bisect start with one term1 and term2' '
822 git bisect start --term-old term2 --term-new term1 &&
823 git bisect term2 $HASH1 &&
824 git bisect term1 $HASH4 &&
826 git bisect term1 >bisect_result &&
827 grep "$HASH2 is the first term1 commit" bisect_result &&
828 git bisect log >log_to_replay.txt &&
832 test_expect_success
'bisect replay with term1 and term2' '
833 git bisect replay log_to_replay.txt >bisect_result &&
834 grep "$HASH2 is the first term1 commit" bisect_result &&
838 test_expect_success
'bisect start term1 term2' '
840 git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
842 git bisect term1 >bisect_result &&
843 grep "$HASH2 is the first term1 commit" bisect_result &&
844 git bisect log >log_to_replay.txt &&
848 test_expect_success
'bisect cannot mix terms' '
850 git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 &&
851 test_must_fail git bisect a &&
852 test_must_fail git bisect b &&
853 test_must_fail git bisect bad &&
854 test_must_fail git bisect good &&
855 test_must_fail git bisect new &&
856 test_must_fail git bisect old
859 test_expect_success
'bisect terms rejects invalid terms' '
861 test_must_fail git bisect start --term-good invalid..term &&
862 test_must_fail git bisect terms --term-bad invalid..term &&
863 test_must_fail git bisect terms --term-good bad &&
864 test_must_fail git bisect terms --term-good old &&
865 test_must_fail git bisect terms --term-good skip &&
866 test_must_fail git bisect terms --term-good reset &&
867 test_path_is_missing .git/BISECT_TERMS
870 test_expect_success
'bisect start --term-* does store terms' '
872 git bisect start --term-bad=one --term-good=two &&
873 git bisect terms >actual &&
874 cat <<-EOF >expected &&
875 Your current terms are two for the old state
876 and one for the new state.
878 test_i18ncmp expected actual &&
879 git bisect terms --term-bad >actual &&
880 echo one >expected &&
881 test_cmp expected actual &&
882 git bisect terms --term-good >actual &&
883 echo two >expected &&
884 test_cmp expected actual
887 test_expect_success
'bisect start takes options and revs in any order' '
889 git bisect start --term-good one $HASH4 \
890 --term-good two --term-bad bad-term \
891 $HASH1 --term-good three -- &&
892 (git bisect terms --term-bad && git bisect terms --term-good) >actual &&
893 printf "%s\n%s\n" bad-term three >expected &&
894 test_cmp expected actual