rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t6030-bisect-porcelain.sh
blob5382e5d21620aea6bd74fdd4a84fb14f0ac644dc
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 automatically find the commit that
270 # added "Ciao" into hello.
271 test_expect_success '"git bisect run" with more complex "git bisect start"' '
272 write_script test_script.sh <<-\EOF &&
273 ! grep Ciao hello >/dev/null
275 git bisect start $HASH4 $HASH1 &&
276 git bisect run ./test_script.sh >my_bisect_log.txt &&
277 grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
278 git bisect reset
281 test_expect_success 'bisect run accepts exit code 126 as bad' '
282 test_when_finished "git bisect reset" &&
283 write_script test_script.sh <<-\EOF &&
284 ! grep Another hello || exit 126 >/dev/null
286 git bisect start &&
287 git bisect good $HASH1 &&
288 git bisect bad $HASH4 &&
289 git bisect run ./test_script.sh >my_bisect_log.txt &&
290 grep "$HASH3 is the first bad commit" my_bisect_log.txt
293 test_expect_success POSIXPERM 'bisect run fails with non-executable test script' '
294 test_when_finished "git bisect reset" &&
295 >not-executable.sh &&
296 chmod -x not-executable.sh &&
297 git bisect start &&
298 git bisect good $HASH1 &&
299 git bisect bad $HASH4 &&
300 test_must_fail git bisect run ./not-executable.sh >my_bisect_log.txt &&
301 ! grep "is the first bad commit" my_bisect_log.txt
304 test_expect_success 'bisect run accepts exit code 127 as bad' '
305 test_when_finished "git bisect reset" &&
306 write_script test_script.sh <<-\EOF &&
307 ! grep Another hello || exit 127 >/dev/null
309 git bisect start &&
310 git bisect good $HASH1 &&
311 git bisect bad $HASH4 &&
312 git bisect run ./test_script.sh >my_bisect_log.txt &&
313 grep "$HASH3 is the first bad commit" my_bisect_log.txt
316 test_expect_success 'bisect run fails with missing test script' '
317 test_when_finished "git bisect reset" &&
318 rm -f does-not-exist.sh &&
319 git bisect start &&
320 git bisect good $HASH1 &&
321 git bisect bad $HASH4 &&
322 test_must_fail git bisect run ./does-not-exist.sh >my_bisect_log.txt &&
323 ! grep "is the first bad commit" my_bisect_log.txt
326 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
327 # but $HASH4 is good,
328 # so we should find $HASH5 as the first bad commit
329 HASH5=
330 test_expect_success 'bisect skip: add line and then a new test' '
331 add_line_into_file "5: Another new line." hello &&
332 HASH5=$(git rev-parse --verify HEAD) &&
333 git bisect start $HASH5 $HASH1 &&
334 git bisect skip &&
335 git bisect good > my_bisect_log.txt &&
336 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
337 git bisect log > log_to_replay.txt &&
338 git bisect reset
341 test_expect_success 'bisect skip and bisect replay' '
342 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
343 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
344 git bisect reset
347 HASH6=
348 test_expect_success 'bisect run & skip: cannot tell between 2' '
349 add_line_into_file "6: Yet a line." hello &&
350 HASH6=$(git rev-parse --verify HEAD) &&
351 write_script test_script.sh <<-\EOF &&
352 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
353 ! grep line hello >/dev/null
355 git bisect start $HASH6 $HASH1 &&
356 test_expect_code 2 git bisect run ./test_script.sh >my_bisect_log.txt &&
357 grep "first bad commit could be any of" my_bisect_log.txt &&
358 ! grep $HASH3 my_bisect_log.txt &&
359 ! grep $HASH6 my_bisect_log.txt &&
360 grep $HASH4 my_bisect_log.txt &&
361 grep $HASH5 my_bisect_log.txt
364 HASH7=
365 test_expect_success 'bisect run & skip: find first bad' '
366 git bisect reset &&
367 add_line_into_file "7: Should be the last line." hello &&
368 HASH7=$(git rev-parse --verify HEAD) &&
369 write_script test_script.sh <<-\EOF &&
370 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
371 sed -ne \$p hello | grep day >/dev/null && exit 125
372 ! grep Yet hello >/dev/null
374 git bisect start $HASH7 $HASH1 &&
375 git bisect run ./test_script.sh >my_bisect_log.txt &&
376 grep "$HASH6 is the first bad commit" my_bisect_log.txt
379 test_expect_success 'bisect skip only one range' '
380 git bisect reset &&
381 git bisect start $HASH7 $HASH1 &&
382 git bisect skip $HASH1..$HASH5 &&
383 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
384 test_must_fail git bisect bad > my_bisect_log.txt &&
385 grep "first bad commit could be any of" my_bisect_log.txt
388 test_expect_success 'bisect skip many ranges' '
389 git bisect start $HASH7 $HASH1 &&
390 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
391 git bisect skip $HASH2 $HASH2.. ..$HASH5 &&
392 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
393 test_must_fail git bisect bad > my_bisect_log.txt &&
394 grep "first bad commit could be any of" my_bisect_log.txt
397 test_expect_success 'bisect starting with a detached HEAD' '
398 git bisect reset &&
399 git checkout main^ &&
400 HEAD=$(git rev-parse --verify HEAD) &&
401 git bisect start &&
402 test $HEAD = $(cat .git/BISECT_START) &&
403 git bisect reset &&
404 test $HEAD = $(git rev-parse --verify HEAD)
407 test_expect_success 'bisect errors out if bad and good are mistaken' '
408 git bisect reset &&
409 test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
410 test_i18ngrep "mistook good and bad" rev_list_error &&
411 git bisect reset
414 test_expect_success 'bisect does not create a "bisect" branch' '
415 git bisect reset &&
416 git bisect start $HASH7 $HASH1 &&
417 git branch bisect &&
418 rev_hash4=$(git rev-parse --verify HEAD) &&
419 test "$rev_hash4" = "$HASH4" &&
420 git branch -D bisect &&
421 git bisect good &&
422 git branch bisect &&
423 rev_hash6=$(git rev-parse --verify HEAD) &&
424 test "$rev_hash6" = "$HASH6" &&
425 git bisect good > my_bisect_log.txt &&
426 grep "$HASH7 is the first bad commit" my_bisect_log.txt &&
427 git bisect reset &&
428 rev_hash6=$(git rev-parse --verify bisect) &&
429 test "$rev_hash6" = "$HASH6" &&
430 git branch -D bisect
433 # This creates a "side" branch to test "siblings" cases.
435 # H1-H2-H3-H4-H5-H6-H7 <--other
437 # S5-S6-S7 <--side
439 test_expect_success 'side branch creation' '
440 git bisect reset &&
441 git checkout -b side $HASH4 &&
442 add_line_into_file "5(side): first line on a side branch" hello2 &&
443 SIDE_HASH5=$(git rev-parse --verify HEAD) &&
444 add_line_into_file "6(side): second line on a side branch" hello2 &&
445 SIDE_HASH6=$(git rev-parse --verify HEAD) &&
446 add_line_into_file "7(side): third line on a side branch" hello2 &&
447 SIDE_HASH7=$(git rev-parse --verify HEAD)
450 test_expect_success 'good merge base when good and bad are siblings' '
451 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
452 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
453 grep $HASH4 my_bisect_log.txt &&
454 git bisect good > my_bisect_log.txt &&
455 ! grep "merge base must be tested" my_bisect_log.txt &&
456 grep $HASH6 my_bisect_log.txt &&
457 git bisect reset
459 test_expect_success 'skipped merge base when good and bad are siblings' '
460 git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt &&
461 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
462 grep $HASH4 my_bisect_log.txt &&
463 git bisect skip > my_bisect_log.txt 2>&1 &&
464 grep "warning" my_bisect_log.txt &&
465 grep $SIDE_HASH6 my_bisect_log.txt &&
466 git bisect reset
469 test_expect_success 'bad merge base when good and bad are siblings' '
470 git bisect start "$HASH7" HEAD > my_bisect_log.txt &&
471 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
472 grep $HASH4 my_bisect_log.txt &&
473 test_must_fail git bisect bad > my_bisect_log.txt 2>&1 &&
474 test_i18ngrep "merge base $HASH4 is bad" my_bisect_log.txt &&
475 test_i18ngrep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt &&
476 git bisect reset
479 # This creates a few more commits (A and B) to test "siblings" cases
480 # when a good and a bad rev have many merge bases.
482 # We should have the following:
484 # H1-H2-H3-H4-H5-H6-H7
485 # \ \ \
486 # S5-A \
487 # \ \
488 # S6-S7----B
490 # And there A and B have 2 merge bases (S5 and H5) that should be
491 # reported by "git merge-base --all A B".
493 test_expect_success 'many merge bases creation' '
494 git checkout "$SIDE_HASH5" &&
495 git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" &&
496 A_HASH=$(git rev-parse --verify HEAD) &&
497 git checkout side &&
498 git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" &&
499 B_HASH=$(git rev-parse --verify HEAD) &&
500 git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt &&
501 test_line_count = 2 merge_bases.txt &&
502 grep "$HASH5" merge_bases.txt &&
503 grep "$SIDE_HASH5" merge_bases.txt
506 # We want to automatically find the merge that
507 # added "line" into hello.
508 test_expect_success '"git bisect run --first-parent" simple case' '
509 git rev-list --first-parent $B_HASH ^$HASH4 >first_parent_chain.txt &&
510 write_script test_script.sh <<-\EOF &&
511 grep $(git rev-parse HEAD) first_parent_chain.txt || exit -1
512 ! grep line hello >/dev/null
514 git bisect start --first-parent &&
515 test_path_is_file ".git/BISECT_FIRST_PARENT" &&
516 git bisect good $HASH4 &&
517 git bisect bad $B_HASH &&
518 git bisect run ./test_script.sh >my_bisect_log.txt &&
519 grep "$B_HASH is the first bad commit" my_bisect_log.txt &&
520 git bisect reset &&
521 test_path_is_missing .git/BISECT_FIRST_PARENT
524 test_expect_success 'good merge bases when good and bad are siblings' '
525 git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt &&
526 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
527 git bisect good > my_bisect_log2.txt &&
528 test_i18ngrep "merge base must be tested" my_bisect_log2.txt &&
531 grep "$SIDE_HASH5" my_bisect_log.txt &&
532 grep "$HASH5" my_bisect_log2.txt
533 } || {
534 grep "$SIDE_HASH5" my_bisect_log2.txt &&
535 grep "$HASH5" my_bisect_log.txt
537 } &&
538 git bisect reset
541 test_expect_success 'optimized merge base checks' '
542 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
543 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
544 grep "$HASH4" my_bisect_log.txt &&
545 git bisect good > my_bisect_log2.txt &&
546 test -f ".git/BISECT_ANCESTORS_OK" &&
547 test "$HASH6" = $(git rev-parse --verify HEAD) &&
548 git bisect bad &&
549 git bisect good "$A_HASH" > my_bisect_log4.txt &&
550 test_i18ngrep "merge base must be tested" my_bisect_log4.txt &&
551 test_path_is_missing ".git/BISECT_ANCESTORS_OK"
554 # This creates another side branch called "parallel" with some files
555 # in some directories, to test bisecting with paths.
557 # We should have the following:
559 # P1-P2-P3-P4-P5-P6-P7
560 # / / /
561 # H1-H2-H3-H4-H5-H6-H7
562 # \ \ \
563 # S5-A \
564 # \ \
565 # S6-S7----B
567 test_expect_success '"parallel" side branch creation' '
568 git bisect reset &&
569 git checkout -b parallel $HASH1 &&
570 mkdir dir1 dir2 &&
571 add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 &&
572 PARA_HASH1=$(git rev-parse --verify HEAD) &&
573 add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
574 PARA_HASH2=$(git rev-parse --verify HEAD) &&
575 add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
576 PARA_HASH3=$(git rev-parse --verify HEAD) &&
577 git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
578 PARA_HASH4=$(git rev-parse --verify HEAD) &&
579 add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
580 PARA_HASH5=$(git rev-parse --verify HEAD) &&
581 add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
582 PARA_HASH6=$(git rev-parse --verify HEAD) &&
583 git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
584 PARA_HASH7=$(git rev-parse --verify HEAD)
587 test_expect_success 'restricting bisection on one dir' '
588 git bisect reset &&
589 git bisect start HEAD $HASH1 -- dir1 &&
590 para1=$(git rev-parse --verify HEAD) &&
591 test "$para1" = "$PARA_HASH1" &&
592 git bisect bad > my_bisect_log.txt &&
593 grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
596 test_expect_success 'restricting bisection on one dir and a file' '
597 git bisect reset &&
598 git bisect start HEAD $HASH1 -- dir1 hello &&
599 para4=$(git rev-parse --verify HEAD) &&
600 test "$para4" = "$PARA_HASH4" &&
601 git bisect bad &&
602 hash3=$(git rev-parse --verify HEAD) &&
603 test "$hash3" = "$HASH3" &&
604 git bisect good &&
605 hash4=$(git rev-parse --verify HEAD) &&
606 test "$hash4" = "$HASH4" &&
607 git bisect good &&
608 para1=$(git rev-parse --verify HEAD) &&
609 test "$para1" = "$PARA_HASH1" &&
610 git bisect good > my_bisect_log.txt &&
611 grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
614 test_expect_success 'skipping away from skipped commit' '
615 git bisect start $PARA_HASH7 $HASH1 &&
616 para4=$(git rev-parse --verify HEAD) &&
617 test "$para4" = "$PARA_HASH4" &&
618 git bisect skip &&
619 hash7=$(git rev-parse --verify HEAD) &&
620 test "$hash7" = "$HASH7" &&
621 git bisect skip &&
622 para3=$(git rev-parse --verify HEAD) &&
623 test "$para3" = "$PARA_HASH3"
626 test_expect_success 'erroring out when using bad path arguments' '
627 test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
628 test_i18ngrep "bad path arguments" error.txt
631 test_expect_success 'test bisection on bare repo - --no-checkout specified' '
632 git clone --bare . bare.nocheckout &&
634 cd bare.nocheckout &&
635 git bisect start --no-checkout &&
636 git bisect good $HASH1 &&
637 git bisect bad $HASH4 &&
638 git bisect run eval \
639 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
640 >../nocheckout.log
641 ) &&
642 grep "$HASH3 is the first bad commit" nocheckout.log
646 test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
647 git clone --bare . bare.defaulted &&
649 cd bare.defaulted &&
650 git bisect start &&
651 git bisect good $HASH1 &&
652 git bisect bad $HASH4 &&
653 git bisect run eval \
654 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
655 >../defaulted.log
656 ) &&
657 grep "$HASH3 is the first bad commit" defaulted.log
661 # This creates a broken branch which cannot be checked out because
662 # the tree created has been deleted.
664 # H1-H2-H3-H4-H5-H6-H7 <--other
666 # S5-S6'-S7'-S8'-S9 <--broken
668 # Commits marked with ' have a missing tree.
670 test_expect_success 'broken branch creation' '
671 git bisect reset &&
672 git checkout -b broken $HASH4 &&
673 git tag BROKEN_HASH4 $HASH4 &&
674 add_line_into_file "5(broken): first line on a broken branch" hello2 &&
675 git tag BROKEN_HASH5 &&
676 mkdir missing &&
677 :> missing/MISSING &&
678 git add missing/MISSING &&
679 git commit -m "6(broken): Added file that will be deleted" &&
680 git tag BROKEN_HASH6 &&
681 deleted=$(git rev-parse --verify HEAD:missing) &&
682 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
683 git tag BROKEN_HASH7 &&
684 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
685 git tag BROKEN_HASH8 &&
686 git rm missing/MISSING &&
687 git commit -m "9(broken): Remove missing file" &&
688 git tag BROKEN_HASH9 &&
689 rm .git/objects/$(test_oid_to_path $deleted)
692 echo "" > expected.ok
693 cat > expected.missing-tree.default <<EOF
694 fatal: unable to read tree $deleted
697 test_expect_success 'bisect fails if tree is broken on start commit' '
698 git bisect reset &&
699 test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
700 test_cmp expected.missing-tree.default error.txt
703 test_expect_success 'bisect fails if tree is broken on trial commit' '
704 git bisect reset &&
705 test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
706 git reset --hard broken &&
707 git checkout broken &&
708 test_cmp expected.missing-tree.default error.txt
711 check_same()
713 echo "Checking $1 is the same as $2" &&
714 test_cmp_rev "$1" "$2"
717 test_expect_success 'bisect: --no-checkout - start commit bad' '
718 git bisect reset &&
719 git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
720 check_same BROKEN_HASH6 BISECT_HEAD &&
721 git bisect reset
724 test_expect_success 'bisect: --no-checkout - trial commit bad' '
725 git bisect reset &&
726 git bisect start broken BROKEN_HASH4 --no-checkout &&
727 check_same BROKEN_HASH6 BISECT_HEAD &&
728 git bisect reset
731 test_expect_success 'bisect: --no-checkout - target before breakage' '
732 git bisect reset &&
733 git bisect start broken BROKEN_HASH4 --no-checkout &&
734 check_same BROKEN_HASH6 BISECT_HEAD &&
735 git bisect bad BISECT_HEAD &&
736 check_same BROKEN_HASH5 BISECT_HEAD &&
737 git bisect bad BISECT_HEAD &&
738 check_same BROKEN_HASH5 bisect/bad &&
739 git bisect reset
742 test_expect_success 'bisect: --no-checkout - target in breakage' '
743 git bisect reset &&
744 git bisect start broken BROKEN_HASH4 --no-checkout &&
745 check_same BROKEN_HASH6 BISECT_HEAD &&
746 git bisect bad BISECT_HEAD &&
747 check_same BROKEN_HASH5 BISECT_HEAD &&
748 test_must_fail git bisect good BISECT_HEAD &&
749 check_same BROKEN_HASH6 bisect/bad &&
750 git bisect reset
753 test_expect_success 'bisect: --no-checkout - target after breakage' '
754 git bisect reset &&
755 git bisect start broken BROKEN_HASH4 --no-checkout &&
756 check_same BROKEN_HASH6 BISECT_HEAD &&
757 git bisect good BISECT_HEAD &&
758 check_same BROKEN_HASH8 BISECT_HEAD &&
759 test_must_fail git bisect good BISECT_HEAD &&
760 check_same BROKEN_HASH9 bisect/bad &&
761 git bisect reset
764 test_expect_success 'bisect: demonstrate identification of damage boundary' "
765 git bisect reset &&
766 git checkout broken &&
767 git bisect start broken main --no-checkout &&
768 test_must_fail git bisect run \"\$SHELL_PATH\" -c '
769 GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
770 git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
771 git pack-objects --stdout >/dev/null < tmp.\$\$
772 rc=\$?
773 rm -f tmp.\$\$
774 test \$rc = 0' &&
775 check_same BROKEN_HASH6 bisect/bad &&
776 git bisect reset
779 cat > expected.bisect-log <<EOF
780 # bad: [$HASH4] Add <4: Ciao for now> into <hello>.
781 # good: [$HASH2] Add <2: A new day for git> into <hello>.
782 git bisect start '$HASH4' '$HASH2'
783 # good: [$HASH3] Add <3: Another new day for git> into <hello>.
784 git bisect good $HASH3
785 # first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
788 test_expect_success 'bisect log: successful result' '
789 git bisect reset &&
790 git bisect start $HASH4 $HASH2 &&
791 git bisect good &&
792 git bisect log >bisect-log.txt &&
793 test_cmp expected.bisect-log bisect-log.txt &&
794 git bisect reset
797 cat > expected.bisect-skip-log <<EOF
798 # bad: [$HASH4] Add <4: Ciao for now> into <hello>.
799 # good: [$HASH2] Add <2: A new day for git> into <hello>.
800 git bisect start '$HASH4' '$HASH2'
801 # skip: [$HASH3] Add <3: Another new day for git> into <hello>.
802 git bisect skip $HASH3
803 # only skipped commits left to test
804 # possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
805 # possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>.
808 test_expect_success 'bisect log: only skip commits left' '
809 git bisect reset &&
810 git bisect start $HASH4 $HASH2 &&
811 test_must_fail git bisect skip &&
812 git bisect log >bisect-skip-log.txt &&
813 test_cmp expected.bisect-skip-log bisect-skip-log.txt &&
814 git bisect reset
817 test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' '
818 git checkout parallel &&
819 git bisect start HEAD $HASH1 &&
820 git bisect good HEAD &&
821 git bisect bad HEAD &&
822 test "$HASH6" = $(git rev-parse --verify HEAD) &&
823 git bisect reset
826 test_expect_success 'bisect starts with only one new' '
827 git bisect reset &&
828 git bisect start &&
829 git bisect new $HASH4 &&
830 git bisect next
833 test_expect_success 'bisect does not start with only one old' '
834 git bisect reset &&
835 git bisect start &&
836 git bisect old $HASH1 &&
837 test_must_fail git bisect next
840 test_expect_success 'bisect start with one new and old' '
841 git bisect reset &&
842 git bisect start &&
843 git bisect old $HASH1 &&
844 git bisect new $HASH4 &&
845 git bisect new &&
846 git bisect new >bisect_result &&
847 grep "$HASH2 is the first new commit" bisect_result &&
848 git bisect log >log_to_replay.txt &&
849 git bisect reset
852 test_expect_success 'bisect replay with old and new' '
853 git bisect replay log_to_replay.txt >bisect_result &&
854 grep "$HASH2 is the first new commit" bisect_result &&
855 git bisect reset
858 test_expect_success 'bisect replay with CRLF log' '
859 append_cr <log_to_replay.txt >log_to_replay_crlf.txt &&
860 git bisect replay log_to_replay_crlf.txt >bisect_result_crlf &&
861 grep "$HASH2 is the first new commit" bisect_result_crlf &&
862 git bisect reset
865 test_expect_success 'bisect cannot mix old/new and good/bad' '
866 git bisect start &&
867 git bisect bad $HASH4 &&
868 test_must_fail git bisect old $HASH1
871 test_expect_success 'bisect terms needs 0 or 1 argument' '
872 git bisect reset &&
873 test_must_fail git bisect terms only-one &&
874 test_must_fail git bisect terms 1 2 &&
875 test_must_fail git bisect terms 2>actual &&
876 echo "error: no terms defined" >expected &&
877 test_cmp expected actual
880 test_expect_success 'bisect terms shows good/bad after start' '
881 git bisect reset &&
882 git bisect start HEAD $HASH1 &&
883 git bisect terms --term-good >actual &&
884 echo good >expected &&
885 test_cmp expected actual &&
886 git bisect terms --term-bad >actual &&
887 echo bad >expected &&
888 test_cmp expected actual
891 test_expect_success 'bisect start with one term1 and term2' '
892 git bisect reset &&
893 git bisect start --term-old term2 --term-new term1 &&
894 git bisect term2 $HASH1 &&
895 git bisect term1 $HASH4 &&
896 git bisect term1 &&
897 git bisect term1 >bisect_result &&
898 grep "$HASH2 is the first term1 commit" bisect_result &&
899 git bisect log >log_to_replay.txt &&
900 git bisect reset
903 test_expect_success 'bisect replay with term1 and term2' '
904 git bisect replay log_to_replay.txt >bisect_result &&
905 grep "$HASH2 is the first term1 commit" bisect_result &&
906 git bisect reset
909 test_expect_success 'bisect start term1 term2' '
910 git bisect reset &&
911 git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
912 git bisect term1 &&
913 git bisect term1 >bisect_result &&
914 grep "$HASH2 is the first term1 commit" bisect_result &&
915 git bisect log >log_to_replay.txt &&
916 git bisect reset
919 test_expect_success 'bisect cannot mix terms' '
920 git bisect reset &&
921 git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 &&
922 test_must_fail git bisect a &&
923 test_must_fail git bisect b &&
924 test_must_fail git bisect bad &&
925 test_must_fail git bisect good &&
926 test_must_fail git bisect new &&
927 test_must_fail git bisect old
930 test_expect_success 'bisect terms rejects invalid terms' '
931 git bisect reset &&
932 test_must_fail git bisect start --term-good &&
933 test_must_fail git bisect start --term-good invalid..term &&
934 test_must_fail git bisect start --term-bad &&
935 test_must_fail git bisect terms --term-bad invalid..term &&
936 test_must_fail git bisect terms --term-good bad &&
937 test_must_fail git bisect terms --term-good old &&
938 test_must_fail git bisect terms --term-good skip &&
939 test_must_fail git bisect terms --term-good reset &&
940 test_path_is_missing .git/BISECT_TERMS
943 test_expect_success 'bisect start --term-* does store terms' '
944 git bisect reset &&
945 git bisect start --term-bad=one --term-good=two &&
946 git bisect terms >actual &&
947 cat <<-EOF >expected &&
948 Your current terms are two for the old state
949 and one for the new state.
951 test_cmp expected actual &&
952 git bisect terms --term-bad >actual &&
953 echo one >expected &&
954 test_cmp expected actual &&
955 git bisect terms --term-good >actual &&
956 echo two >expected &&
957 test_cmp expected actual
960 test_expect_success 'bisect start takes options and revs in any order' '
961 git bisect reset &&
962 git bisect start --term-good one $HASH4 \
963 --term-good two --term-bad bad-term \
964 $HASH1 --term-good three -- &&
965 (git bisect terms --term-bad && git bisect terms --term-good) >actual &&
966 printf "%s\n%s\n" bad-term three >expected &&
967 test_cmp expected actual
970 # Bisect is started with --term-new and --term-old arguments,
971 # then skip. The HEAD should be changed.
972 test_expect_success 'bisect skip works with --term*' '
973 git bisect reset &&
974 git bisect start --term-new=fixed --term-old=unfixed HEAD $HASH1 &&
975 hash_skipped_from=$(git rev-parse --verify HEAD) &&
976 git bisect skip &&
977 hash_skipped_to=$(git rev-parse --verify HEAD) &&
978 test "$hash_skipped_from" != "$hash_skipped_to"
981 test_expect_success 'git bisect reset cleans bisection state properly' '
982 git bisect reset &&
983 git bisect start &&
984 git bisect good $HASH1 &&
985 git bisect bad $HASH4 &&
986 git bisect reset &&
987 test -z "$(git for-each-ref "refs/bisect/*")" &&
988 test_path_is_missing ".git/BISECT_EXPECTED_REV" &&
989 test_path_is_missing ".git/BISECT_ANCESTORS_OK" &&
990 test_path_is_missing ".git/BISECT_LOG" &&
991 test_path_is_missing ".git/BISECT_RUN" &&
992 test_path_is_missing ".git/BISECT_TERMS" &&
993 test_path_is_missing ".git/head-name" &&
994 test_path_is_missing ".git/BISECT_HEAD" &&
995 test_path_is_missing ".git/BISECT_START"
998 test_expect_success 'bisect handles annotated tags' '
999 test_commit commit-one &&
1000 git tag -m foo tag-one &&
1001 test_commit commit-two &&
1002 git tag -m foo tag-two &&
1003 git bisect start &&
1004 git bisect good tag-one &&
1005 git bisect bad tag-two >output &&
1006 bad=$(git rev-parse --verify tag-two^{commit}) &&
1007 grep "$bad is the first bad commit" output
1010 test_expect_success 'bisect run fails with exit code equals or greater than 128' '
1011 write_script test_script.sh <<-\EOF &&
1012 exit 128
1014 test_must_fail git bisect run ./test_script.sh &&
1015 write_script test_script.sh <<-\EOF &&
1016 exit 255
1018 test_must_fail git bisect run ./test_script.sh
1021 test_expect_success 'bisect visualize with a filename with dash and space' '
1022 echo "My test line" >>"./-hello 2" &&
1023 git add -- "./-hello 2" &&
1024 git commit --quiet -m "Add test line" -- "./-hello 2" &&
1025 git bisect visualize -p -- "-hello 2"
1028 test_done