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