]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6030-bisect-porcelain.sh
cmd_bisect__helper: defer parsing no-checkout flag
[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
a17c4101
CC
9. ./test-lib.sh
10
11add_line_into_file()
12{
13 _line=$1
14 _file=$2
15
16 if [ -f "$_file" ]; then
17 echo "$_line" >> $_file || return $?
18 MSG="Add <$_line> into <$_file>."
19 else
20 echo "$_line" > $_file || return $?
21 git add $_file || return $?
22 MSG="Create file <$_file> with <$_line> inside."
23 fi
24
ab69e89c 25 test_tick
3604e7c5 26 git commit --quiet -m "$MSG" $_file
a17c4101
CC
27}
28
29HASH1=
ab69e89c 30HASH2=
a17c4101
CC
31HASH3=
32HASH4=
33
ab69e89c
JH
34test_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) &&
a17c4101 37 add_line_into_file "2: A new day for git" hello &&
ab69e89c 38 HASH2=$(git rev-parse --verify HEAD) &&
a17c4101 39 add_line_into_file "3: Another new day for git" hello &&
ab69e89c 40 HASH3=$(git rev-parse --verify HEAD) &&
a17c4101 41 add_line_into_file "4: Ciao for now" hello &&
ab69e89c
JH
42 HASH4=$(git rev-parse --verify HEAD)
43'
a17c4101 44
0a5280a9 45test_expect_success 'bisect starts with only one bad' '
4f506716
JH
46 git bisect reset &&
47 git bisect start &&
0a5280a9
JH
48 git bisect bad $HASH4 &&
49 git bisect next
4f506716
JH
50'
51
f9487929 52test_expect_success 'bisect does not start with only one good' '
4f506716
JH
53 git bisect reset &&
54 git bisect start &&
e4e6e8b4
JK
55 git bisect good $HASH1 &&
56 test_must_fail git bisect next
4f506716
JH
57'
58
59test_expect_success 'bisect start with one bad and good' '
60 git bisect reset &&
61 git bisect start &&
62 git bisect good $HASH1 &&
63 git bisect bad $HASH4 &&
64 git bisect next
65'
66
d3e54c88 67test_expect_success 'bisect fails if given any junk instead of revs' '
e3389075 68 git bisect reset &&
d3e54c88
CC
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/*")" &&
b890fa33 72 test -z "$(ls .git/BISECT_* 2>/dev/null)" &&
e3389075
CC
73 git bisect start &&
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 &&
d3e54c88 80 test -z "$(git for-each-ref "refs/bisect/*")" &&
e3389075
CC
81 git bisect good $HASH1 &&
82 git bisect bad $HASH4
4f506716
JH
83'
84
fce0499f
CC
85test_expect_success 'bisect reset: back in the master branch' '
86 git bisect reset &&
87 echo "* master" > branch.expect &&
88 git branch > branch.output &&
89 cmp branch.expect branch.output
90'
91
92test_expect_success 'bisect reset: back in another branch' '
93 git checkout -b other &&
94 git bisect start &&
95 git bisect good $HASH1 &&
96 git bisect bad $HASH3 &&
97 git bisect reset &&
98 echo " master" > branch.expect &&
99 echo "* other" >> branch.expect &&
100 git branch > branch.output &&
101 cmp branch.expect branch.output
102'
103
104test_expect_success 'bisect reset when not bisecting' '
105 git bisect reset &&
106 git branch > branch.output &&
107 cmp branch.expect branch.output
108'
109
947a604b
CC
110test_expect_success 'bisect reset removes packed refs' '
111 git bisect reset &&
112 git bisect start &&
113 git bisect good $HASH1 &&
114 git bisect bad $HASH3 &&
115 git pack-refs --all --prune &&
116 git bisect next &&
117 git bisect reset &&
118 test -z "$(git for-each-ref "refs/bisect/*")" &&
119 test -z "$(git for-each-ref "refs/heads/bisect")"
120'
121
b704a8b3
JS
122test_expect_success 'bisect reset removes bisect state after --no-checkout' '
123 git bisect reset &&
124 git bisect start --no-checkout &&
125 git bisect good $HASH1 &&
126 git bisect bad $HASH3 &&
127 git bisect next &&
128 git bisect reset &&
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")"
132'
133
d3aca585
CC
134test_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 -- &&
138 git bisect good &&
139 git bisect start $HASH4 $HASH1 -- &&
140 git bisect bad &&
141 git bisect reset &&
142 git branch > branch.output &&
143 grep "* other" branch.output > /dev/null
144'
145
4764f464
JS
146test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' '
147 git bisect reset &&
d3aca585
CC
148 test_must_fail git bisect start $HASH4 foo -- &&
149 git branch > branch.output &&
150 grep "* other" branch.output > /dev/null &&
085ba9b5 151 test_path_is_missing .git/BISECT_START
d3aca585
CC
152'
153
4764f464
JS
154test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
155 git bisect start $HASH4 $HASH1 -- &&
156 git bisect good &&
157 cp .git/BISECT_START saved &&
158 test_must_fail git bisect start $HASH4 foo -- &&
159 git branch > branch.output &&
6deab24d 160 test_i18ngrep "* (no branch, bisect started on other)" branch.output > /dev/null &&
4764f464
JS
161 test_cmp saved .git/BISECT_START
162'
ba963de8 163test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
d3aca585
CC
164 git bisect start $HASH4 $HASH1 -- &&
165 git bisect good &&
166 test_must_fail git bisect start $HASH1 $HASH4 -- &&
167 git branch > branch.output &&
168 grep "* other" branch.output > /dev/null &&
085ba9b5 169 test_path_is_missing .git/BISECT_START
d3aca585
CC
170'
171
ba963de8 172test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
d3aca585
CC
173 echo "temp stuff" > hello &&
174 test_must_fail git bisect start $HASH4 $HASH1 -- &&
175 git branch &&
176 git branch > branch.output &&
177 grep "* other" branch.output > /dev/null &&
085ba9b5 178 test_path_is_missing .git/BISECT_START &&
ba963de8
CC
179 test -z "$(git for-each-ref "refs/bisect/*")" &&
180 git checkout HEAD hello
d3aca585
CC
181'
182
97e1c51e
CC
183# $HASH1 is good, $HASH4 is bad, we skip $HASH3
184# but $HASH2 is bad,
185# so we should find $HASH2 as the first bad commit
41ccfdd9 186test_expect_success 'bisect skip: successful result' '
e4e6e8b4 187 test_when_finished git bisect reset &&
97e1c51e
CC
188 git bisect reset &&
189 git bisect start $HASH4 $HASH1 &&
190 git bisect skip &&
191 git bisect bad > my_bisect_log.txt &&
e4e6e8b4 192 grep "$HASH2 is the first bad commit" my_bisect_log.txt
97e1c51e
CC
193'
194
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
198test_expect_success 'bisect skip: cannot tell between 3 commits' '
e4e6e8b4 199 test_when_finished git bisect reset &&
97e1c51e 200 git bisect start $HASH4 $HASH1 &&
e4e6e8b4
JK
201 git bisect skip &&
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
97e1c51e
CC
208'
209
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
214test_expect_success 'bisect skip: cannot tell between 2 commits' '
e4e6e8b4 215 test_when_finished git bisect reset &&
97e1c51e 216 git bisect start $HASH4 $HASH1 &&
e4e6e8b4
JK
217 git bisect skip &&
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
97e1c51e
CC
224'
225
1b249ffe
CC
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
230test_expect_success 'bisect skip: with commit both bad and skipped' '
e4e6e8b4 231 test_when_finished git bisect reset &&
1b249ffe
CC
232 git bisect start &&
233 git bisect skip &&
234 git bisect bad &&
235 git bisect good $HASH1 &&
236 git bisect skip &&
e4e6e8b4
JK
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
97e1c51e
CC
243'
244
a17c4101 245# We want to automatically find the commit that
15a4802a
AL
246# added "Another" into hello.
247test_expect_success '"git bisect run" simple case' '
248 write_script test_script.sh <<-\EOF &&
249 ! grep Another hello >/dev/null
250 EOF
251 git bisect start &&
252 git bisect good $HASH1 &&
253 git bisect bad $HASH4 &&
254 git bisect run ./test_script.sh >my_bisect_log.txt &&
255 grep "$HASH3 is the first bad commit" my_bisect_log.txt &&
256 git bisect reset
257'
38a47fd6
CC
258
259# We want to automatically find the commit that
15a4802a
AL
260# added "Ciao" into hello.
261test_expect_success '"git bisect run" with more complex "git bisect start"' '
262 write_script test_script.sh <<-\EOF &&
263 ! grep Ciao hello >/dev/null
264 EOF
265 git bisect start $HASH4 $HASH1 &&
266 git bisect run ./test_script.sh >my_bisect_log.txt &&
267 grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
268 git bisect reset
269'
a17c4101 270
97e1c51e
CC
271# $HASH1 is good, $HASH5 is bad, we skip $HASH3
272# but $HASH4 is good,
273# so we should find $HASH5 as the first bad commit
274HASH5=
275test_expect_success 'bisect skip: add line and then a new test' '
276 add_line_into_file "5: Another new line." hello &&
277 HASH5=$(git rev-parse --verify HEAD) &&
278 git bisect start $HASH5 $HASH1 &&
279 git bisect skip &&
280 git bisect good > my_bisect_log.txt &&
21d0bc2f 281 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
fce0499f 282 git bisect log > log_to_replay.txt &&
37f9fd0d
CC
283 git bisect reset
284'
285
286test_expect_success 'bisect skip and bisect replay' '
287 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
21d0bc2f 288 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
97e1c51e
CC
289 git bisect reset
290'
291
71b0251c
CC
292HASH6=
293test_expect_success 'bisect run & skip: cannot tell between 2' '
294 add_line_into_file "6: Yet a line." hello &&
295 HASH6=$(git rev-parse --verify HEAD) &&
15a4802a
AL
296 write_script test_script.sh <<-\EOF &&
297 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
298 ! grep line hello >/dev/null
299 EOF
71b0251c 300 git bisect start $HASH6 $HASH1 &&
15a4802a
AL
301 test_expect_code 2 git bisect run ./test_script.sh >my_bisect_log.txt &&
302 grep "first bad commit could be any of" my_bisect_log.txt &&
303 ! grep $HASH3 my_bisect_log.txt &&
304 ! grep $HASH6 my_bisect_log.txt &&
305 grep $HASH4 my_bisect_log.txt &&
306 grep $HASH5 my_bisect_log.txt
71b0251c
CC
307'
308
309HASH7=
310test_expect_success 'bisect run & skip: find first bad' '
311 git bisect reset &&
312 add_line_into_file "7: Should be the last line." hello &&
313 HASH7=$(git rev-parse --verify HEAD) &&
15a4802a
AL
314 write_script test_script.sh <<-\EOF &&
315 sed -ne \$p hello | grep Ciao >/dev/null && exit 125
316 sed -ne \$p hello | grep day >/dev/null && exit 125
317 ! grep Yet hello >/dev/null
318 EOF
71b0251c 319 git bisect start $HASH7 $HASH1 &&
15a4802a 320 git bisect run ./test_script.sh >my_bisect_log.txt &&
21d0bc2f 321 grep "$HASH6 is the first bad commit" my_bisect_log.txt
71b0251c
CC
322'
323
1a66a489
CC
324test_expect_success 'bisect skip only one range' '
325 git bisect reset &&
326 git bisect start $HASH7 $HASH1 &&
327 git bisect skip $HASH1..$HASH5 &&
328 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
329 test_must_fail git bisect bad > my_bisect_log.txt &&
330 grep "first bad commit could be any of" my_bisect_log.txt
331'
ce32660e 332
1a66a489
CC
333test_expect_success 'bisect skip many ranges' '
334 git bisect start $HASH7 $HASH1 &&
335 test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
336 git bisect skip $HASH2 $HASH2.. ..$HASH5 &&
337 test "$HASH6" = "$(git rev-parse --verify HEAD)" &&
338 test_must_fail git bisect bad > my_bisect_log.txt &&
339 grep "first bad commit could be any of" my_bisect_log.txt
340'
341
342test_expect_success 'bisect starting with a detached HEAD' '
ce32660e
JS
343 git bisect reset &&
344 git checkout master^ &&
345 HEAD=$(git rev-parse --verify HEAD) &&
346 git bisect start &&
b577bb92 347 test $HEAD = $(cat .git/BISECT_START) &&
ce32660e
JS
348 git bisect reset &&
349 test $HEAD = $(git rev-parse --verify HEAD)
ee831f7d
GP
350'
351
42ba5ee7
CC
352test_expect_success 'bisect errors out if bad and good are mistaken' '
353 git bisect reset &&
354 test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
14dc4899 355 test_i18ngrep "mistook good and bad" rev_list_error &&
42ba5ee7
CC
356 git bisect reset
357'
358
634f2464
CC
359test_expect_success 'bisect does not create a "bisect" branch' '
360 git bisect reset &&
361 git bisect start $HASH7 $HASH1 &&
362 git branch bisect &&
363 rev_hash4=$(git rev-parse --verify HEAD) &&
364 test "$rev_hash4" = "$HASH4" &&
365 git branch -D bisect &&
366 git bisect good &&
367 git branch bisect &&
368 rev_hash6=$(git rev-parse --verify HEAD) &&
369 test "$rev_hash6" = "$HASH6" &&
370 git bisect good > my_bisect_log.txt &&
21d0bc2f 371 grep "$HASH7 is the first bad commit" my_bisect_log.txt &&
634f2464
CC
372 git bisect reset &&
373 rev_hash6=$(git rev-parse --verify bisect) &&
374 test "$rev_hash6" = "$HASH6" &&
375 git branch -D bisect
376'
377
f821d089
CC
378# This creates a "side" branch to test "siblings" cases.
379#
380# H1-H2-H3-H4-H5-H6-H7 <--other
381# \
382# S5-S6-S7 <--side
383#
384test_expect_success 'side branch creation' '
385 git bisect reset &&
386 git checkout -b side $HASH4 &&
387 add_line_into_file "5(side): first line on a side branch" hello2 &&
388 SIDE_HASH5=$(git rev-parse --verify HEAD) &&
389 add_line_into_file "6(side): second line on a side branch" hello2 &&
390 SIDE_HASH6=$(git rev-parse --verify HEAD) &&
391 add_line_into_file "7(side): third line on a side branch" hello2 &&
392 SIDE_HASH7=$(git rev-parse --verify HEAD)
393'
394
395test_expect_success 'good merge base when good and bad are siblings' '
396 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
14dc4899 397 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
f821d089
CC
398 grep $HASH4 my_bisect_log.txt &&
399 git bisect good > my_bisect_log.txt &&
c7cf9566 400 ! grep "merge base must be tested" my_bisect_log.txt &&
f821d089
CC
401 grep $HASH6 my_bisect_log.txt &&
402 git bisect reset
403'
404test_expect_success 'skipped merge base when good and bad are siblings' '
405 git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt &&
14dc4899 406 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
f821d089
CC
407 grep $HASH4 my_bisect_log.txt &&
408 git bisect skip > my_bisect_log.txt 2>&1 &&
bd757c18 409 grep "warning" my_bisect_log.txt &&
f821d089
CC
410 grep $SIDE_HASH6 my_bisect_log.txt &&
411 git bisect reset
412'
413
414test_expect_success 'bad merge base when good and bad are siblings' '
415 git bisect start "$HASH7" HEAD > my_bisect_log.txt &&
14dc4899 416 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
f821d089
CC
417 grep $HASH4 my_bisect_log.txt &&
418 test_must_fail git bisect bad > my_bisect_log.txt 2>&1 &&
14dc4899
VA
419 test_i18ngrep "merge base $HASH4 is bad" my_bisect_log.txt &&
420 test_i18ngrep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt &&
f821d089
CC
421 git bisect reset
422'
423
424# This creates a few more commits (A and B) to test "siblings" cases
425# when a good and a bad rev have many merge bases.
426#
427# We should have the following:
428#
429# H1-H2-H3-H4-H5-H6-H7
430# \ \ \
431# S5-A \
432# \ \
433# S6-S7----B
434#
435# And there A and B have 2 merge bases (S5 and H5) that should be
436# reported by "git merge-base --all A B".
437#
438test_expect_success 'many merge bases creation' '
439 git checkout "$SIDE_HASH5" &&
440 git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" &&
441 A_HASH=$(git rev-parse --verify HEAD) &&
442 git checkout side &&
443 git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" &&
444 B_HASH=$(git rev-parse --verify HEAD) &&
445 git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt &&
3fb0459b 446 test_line_count = 2 merge_bases.txt &&
f821d089
CC
447 grep "$HASH5" merge_bases.txt &&
448 grep "$SIDE_HASH5" merge_bases.txt
449'
450
451test_expect_success 'good merge bases when good and bad are siblings' '
452 git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt &&
14dc4899 453 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
f821d089 454 git bisect good > my_bisect_log2.txt &&
14dc4899 455 test_i18ngrep "merge base must be tested" my_bisect_log2.txt &&
f821d089
CC
456 {
457 {
458 grep "$SIDE_HASH5" my_bisect_log.txt &&
459 grep "$HASH5" my_bisect_log2.txt
460 } || {
461 grep "$SIDE_HASH5" my_bisect_log2.txt &&
462 grep "$HASH5" my_bisect_log.txt
463 }
464 } &&
465 git bisect reset
466'
467
c9c4e2d5 468test_expect_success 'optimized merge base checks' '
c9c4e2d5 469 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
14dc4899 470 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
c9c4e2d5 471 grep "$HASH4" my_bisect_log.txt &&
c9c4e2d5
CC
472 git bisect good > my_bisect_log2.txt &&
473 test -f ".git/BISECT_ANCESTORS_OK" &&
474 test "$HASH6" = $(git rev-parse --verify HEAD) &&
675ef6ba 475 git bisect bad &&
c9c4e2d5 476 git bisect good "$A_HASH" > my_bisect_log4.txt &&
14dc4899 477 test_i18ngrep "merge base must be tested" my_bisect_log4.txt &&
085ba9b5 478 test_path_is_missing ".git/BISECT_ANCESTORS_OK"
c9c4e2d5
CC
479'
480
b74d7efb
CC
481# This creates another side branch called "parallel" with some files
482# in some directories, to test bisecting with paths.
483#
484# We should have the following:
485#
486# P1-P2-P3-P4-P5-P6-P7
487# / / /
488# H1-H2-H3-H4-H5-H6-H7
489# \ \ \
490# S5-A \
491# \ \
492# S6-S7----B
493#
494test_expect_success '"parallel" side branch creation' '
495 git bisect reset &&
496 git checkout -b parallel $HASH1 &&
497 mkdir dir1 dir2 &&
498 add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 &&
499 PARA_HASH1=$(git rev-parse --verify HEAD) &&
500 add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
501 PARA_HASH2=$(git rev-parse --verify HEAD) &&
502 add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
a48fcd83 503 PARA_HASH3=$(git rev-parse --verify HEAD) &&
b74d7efb 504 git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
a48fcd83 505 PARA_HASH4=$(git rev-parse --verify HEAD) &&
b74d7efb 506 add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
a48fcd83 507 PARA_HASH5=$(git rev-parse --verify HEAD) &&
b74d7efb 508 add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
a48fcd83 509 PARA_HASH6=$(git rev-parse --verify HEAD) &&
b74d7efb
CC
510 git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
511 PARA_HASH7=$(git rev-parse --verify HEAD)
512'
513
514test_expect_success 'restricting bisection on one dir' '
515 git bisect reset &&
516 git bisect start HEAD $HASH1 -- dir1 &&
517 para1=$(git rev-parse --verify HEAD) &&
518 test "$para1" = "$PARA_HASH1" &&
519 git bisect bad > my_bisect_log.txt &&
21d0bc2f 520 grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
b74d7efb
CC
521'
522
523test_expect_success 'restricting bisection on one dir and a file' '
524 git bisect reset &&
525 git bisect start HEAD $HASH1 -- dir1 hello &&
526 para4=$(git rev-parse --verify HEAD) &&
527 test "$para4" = "$PARA_HASH4" &&
528 git bisect bad &&
529 hash3=$(git rev-parse --verify HEAD) &&
530 test "$hash3" = "$HASH3" &&
531 git bisect good &&
532 hash4=$(git rev-parse --verify HEAD) &&
533 test "$hash4" = "$HASH4" &&
534 git bisect good &&
535 para1=$(git rev-parse --verify HEAD) &&
536 test "$para1" = "$PARA_HASH1" &&
537 git bisect good > my_bisect_log.txt &&
21d0bc2f 538 grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
b74d7efb
CC
539'
540
a66037c9
CC
541test_expect_success 'skipping away from skipped commit' '
542 git bisect start $PARA_HASH7 $HASH1 &&
543 para4=$(git rev-parse --verify HEAD) &&
544 test "$para4" = "$PARA_HASH4" &&
545 git bisect skip &&
546 hash7=$(git rev-parse --verify HEAD) &&
547 test "$hash7" = "$HASH7" &&
548 git bisect skip &&
ebc9529f
CC
549 para3=$(git rev-parse --verify HEAD) &&
550 test "$para3" = "$PARA_HASH3"
a66037c9
CC
551'
552
8f69f72f
CC
553test_expect_success 'erroring out when using bad path parameters' '
554 test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
14dc4899 555 test_i18ngrep "bad path parameters" error.txt
8f69f72f
CC
556'
557
24c51280
JS
558test_expect_success 'test bisection on bare repo - --no-checkout specified' '
559 git clone --bare . bare.nocheckout &&
560 (
561 cd bare.nocheckout &&
562 git bisect start --no-checkout &&
563 git bisect good $HASH1 &&
564 git bisect bad $HASH4 &&
565 git bisect run eval \
566 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
e4e6e8b4 567 >../nocheckout.log
24c51280
JS
568 ) &&
569 grep "$HASH3 is the first bad commit" nocheckout.log
570'
571
572
573test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
574 git clone --bare . bare.defaulted &&
575 (
576 cd bare.defaulted &&
577 git bisect start &&
578 git bisect good $HASH1 &&
579 git bisect bad $HASH4 &&
580 git bisect run eval \
581 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
e4e6e8b4 582 >../defaulted.log
24c51280
JS
583 ) &&
584 grep "$HASH3 is the first bad commit" defaulted.log
585'
586
a17c4101 587#
d3dfeedf
JS
588# This creates a broken branch which cannot be checked out because
589# the tree created has been deleted.
a17c4101 590#
d3dfeedf
JS
591# H1-H2-H3-H4-H5-H6-H7 <--other
592# \
593# S5-S6'-S7'-S8'-S9 <--broken
594#
595# Commits marked with ' have a missing tree.
596#
597test_expect_success 'broken branch creation' '
598 git bisect reset &&
599 git checkout -b broken $HASH4 &&
600 git tag BROKEN_HASH4 $HASH4 &&
601 add_line_into_file "5(broken): first line on a broken branch" hello2 &&
602 git tag BROKEN_HASH5 &&
603 mkdir missing &&
604 :> missing/MISSING &&
605 git add missing/MISSING &&
e4e6e8b4 606 git commit -m "6(broken): Added file that will be deleted" &&
d3dfeedf 607 git tag BROKEN_HASH6 &&
0795aed0 608 deleted=$(git rev-parse --verify HEAD:missing) &&
d3dfeedf
JS
609 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
610 git tag BROKEN_HASH7 &&
611 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
612 git tag BROKEN_HASH8 &&
613 git rm missing/MISSING &&
e4e6e8b4 614 git commit -m "9(broken): Remove missing file" &&
d3dfeedf 615 git tag BROKEN_HASH9 &&
0795aed0 616 rm .git/objects/$(test_oid_to_path $deleted)
d3dfeedf
JS
617'
618
619echo "" > expected.ok
620cat > expected.missing-tree.default <<EOF
0795aed0 621fatal: unable to read tree $deleted
d3dfeedf
JS
622EOF
623
624test_expect_success 'bisect fails if tree is broken on start commit' '
625 git bisect reset &&
626 test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
627 test_cmp expected.missing-tree.default error.txt
628'
629
630test_expect_success 'bisect fails if tree is broken on trial commit' '
631 git bisect reset &&
632 test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
633 git reset --hard broken &&
634 git checkout broken &&
635 test_cmp expected.missing-tree.default error.txt
636'
637
b704a8b3
JS
638check_same()
639{
640 echo "Checking $1 is the same as $2" &&
5d77298d 641 test_cmp_rev "$1" "$2"
b704a8b3
JS
642}
643
644test_expect_success 'bisect: --no-checkout - start commit bad' '
645 git bisect reset &&
646 git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
647 check_same BROKEN_HASH6 BISECT_HEAD &&
648 git bisect reset
649'
650
651test_expect_success 'bisect: --no-checkout - trial commit bad' '
652 git bisect reset &&
653 git bisect start broken BROKEN_HASH4 --no-checkout &&
654 check_same BROKEN_HASH6 BISECT_HEAD &&
655 git bisect reset
656'
657
658test_expect_success 'bisect: --no-checkout - target before breakage' '
659 git bisect reset &&
660 git bisect start broken BROKEN_HASH4 --no-checkout &&
661 check_same BROKEN_HASH6 BISECT_HEAD &&
662 git bisect bad BISECT_HEAD &&
663 check_same BROKEN_HASH5 BISECT_HEAD &&
664 git bisect bad BISECT_HEAD &&
665 check_same BROKEN_HASH5 bisect/bad &&
666 git bisect reset
667'
668
669test_expect_success 'bisect: --no-checkout - target in breakage' '
670 git bisect reset &&
671 git bisect start broken BROKEN_HASH4 --no-checkout &&
672 check_same BROKEN_HASH6 BISECT_HEAD &&
673 git bisect bad BISECT_HEAD &&
674 check_same BROKEN_HASH5 BISECT_HEAD &&
b02be8b9 675 test_must_fail git bisect good BISECT_HEAD &&
b704a8b3
JS
676 check_same BROKEN_HASH6 bisect/bad &&
677 git bisect reset
678'
679
680test_expect_success 'bisect: --no-checkout - target after breakage' '
681 git bisect reset &&
682 git bisect start broken BROKEN_HASH4 --no-checkout &&
683 check_same BROKEN_HASH6 BISECT_HEAD &&
684 git bisect good BISECT_HEAD &&
685 check_same BROKEN_HASH8 BISECT_HEAD &&
b02be8b9 686 test_must_fail git bisect good BISECT_HEAD &&
b704a8b3
JS
687 check_same BROKEN_HASH9 bisect/bad &&
688 git bisect reset
689'
690
691test_expect_success 'bisect: demonstrate identification of damage boundary' "
692 git bisect reset &&
693 git checkout broken &&
694 git bisect start broken master --no-checkout &&
b02be8b9 695 test_must_fail git bisect run \"\$SHELL_PATH\" -c '
b704a8b3
JS
696 GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
697 git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
698 git pack-objects --stdout >/dev/null < tmp.\$\$
699 rc=\$?
700 rm -f tmp.\$\$
701 test \$rc = 0' &&
702 check_same BROKEN_HASH6 bisect/bad &&
703 git bisect reset
704"
705
a7f8b8ac 706cat > expected.bisect-log <<EOF
0795aed0 707# bad: [$HASH4] Add <4: Ciao for now> into <hello>.
708# good: [$HASH2] Add <2: A new day for git> into <hello>.
709git bisect start '$HASH4' '$HASH2'
710# good: [$HASH3] Add <3: Another new day for git> into <hello>.
711git bisect good $HASH3
712# first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
a7f8b8ac
TH
713EOF
714
2e3a16b2 715test_expect_success 'bisect log: successful result' '
a7f8b8ac
TH
716 git bisect reset &&
717 git bisect start $HASH4 $HASH2 &&
718 git bisect good &&
719 git bisect log >bisect-log.txt &&
720 test_cmp expected.bisect-log bisect-log.txt &&
721 git bisect reset
722'
723
f989cac9 724cat > expected.bisect-skip-log <<EOF
0795aed0 725# bad: [$HASH4] Add <4: Ciao for now> into <hello>.
726# good: [$HASH2] Add <2: A new day for git> into <hello>.
727git bisect start '$HASH4' '$HASH2'
728# skip: [$HASH3] Add <3: Another new day for git> into <hello>.
729git bisect skip $HASH3
f989cac9 730# only skipped commits left to test
0795aed0 731# possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
732# possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>.
f989cac9
TH
733EOF
734
735test_expect_success 'bisect log: only skip commits left' '
736 git bisect reset &&
737 git bisect start $HASH4 $HASH2 &&
738 test_must_fail git bisect skip &&
739 git bisect log >bisect-skip-log.txt &&
740 test_cmp expected.bisect-skip-log bisect-skip-log.txt &&
741 git bisect reset
742'
743
07913d5a
CC
744test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' '
745 git checkout parallel &&
746 git bisect start HEAD $HASH1 &&
747 git bisect good HEAD &&
748 git bisect bad HEAD &&
749 test "$HASH6" = $(git rev-parse --verify HEAD) &&
750 git bisect reset
751'
752
21e5cfd8
AD
753test_expect_success 'bisect starts with only one new' '
754 git bisect reset &&
755 git bisect start &&
756 git bisect new $HASH4 &&
757 git bisect next
758'
759
760test_expect_success 'bisect does not start with only one old' '
761 git bisect reset &&
762 git bisect start &&
763 git bisect old $HASH1 &&
764 test_must_fail git bisect next
765'
766
767test_expect_success 'bisect start with one new and old' '
768 git bisect reset &&
769 git bisect start &&
770 git bisect old $HASH1 &&
771 git bisect new $HASH4 &&
772 git bisect new &&
773 git bisect new >bisect_result &&
774 grep "$HASH2 is the first new commit" bisect_result &&
775 git bisect log >log_to_replay.txt &&
776 git bisect reset
777'
778
779test_expect_success 'bisect replay with old and new' '
780 git bisect replay log_to_replay.txt >bisect_result &&
781 grep "$HASH2 is the first new commit" bisect_result &&
782 git bisect reset
783'
784
6c722cbe
CW
785test_expect_success 'bisect replay with CRLF log' '
786 append_cr <log_to_replay.txt >log_to_replay_crlf.txt &&
787 git bisect replay log_to_replay_crlf.txt >bisect_result_crlf &&
788 grep "$HASH2 is the first new commit" bisect_result_crlf &&
789 git bisect reset
790'
791
21e5cfd8
AD
792test_expect_success 'bisect cannot mix old/new and good/bad' '
793 git bisect start &&
794 git bisect bad $HASH4 &&
795 test_must_fail git bisect old $HASH1
796'
797
21b55e33
MM
798test_expect_success 'bisect terms needs 0 or 1 argument' '
799 git bisect reset &&
800 test_must_fail git bisect terms only-one &&
801 test_must_fail git bisect terms 1 2 &&
802 test_must_fail git bisect terms 2>actual &&
450ebb73 803 echo "error: no terms defined" >expected &&
c9e6ce41 804 test_i18ncmp expected actual
21b55e33
MM
805'
806
807test_expect_success 'bisect terms shows good/bad after start' '
808 git bisect reset &&
809 git bisect start HEAD $HASH1 &&
810 git bisect terms --term-good >actual &&
811 echo good >expected &&
812 test_cmp expected actual &&
813 git bisect terms --term-bad >actual &&
814 echo bad >expected &&
815 test_cmp expected actual
816'
817
06e6a745
MM
818test_expect_success 'bisect start with one term1 and term2' '
819 git bisect reset &&
820 git bisect start --term-old term2 --term-new term1 &&
821 git bisect term2 $HASH1 &&
822 git bisect term1 $HASH4 &&
823 git bisect term1 &&
824 git bisect term1 >bisect_result &&
825 grep "$HASH2 is the first term1 commit" bisect_result &&
826 git bisect log >log_to_replay.txt &&
827 git bisect reset
828'
829
830test_expect_success 'bisect replay with term1 and term2' '
831 git bisect replay log_to_replay.txt >bisect_result &&
832 grep "$HASH2 is the first term1 commit" bisect_result &&
833 git bisect reset
834'
835
836test_expect_success 'bisect start term1 term2' '
837 git bisect reset &&
838 git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
839 git bisect term1 &&
840 git bisect term1 >bisect_result &&
841 grep "$HASH2 is the first term1 commit" bisect_result &&
842 git bisect log >log_to_replay.txt &&
843 git bisect reset
844'
845
846test_expect_success 'bisect cannot mix terms' '
847 git bisect reset &&
848 git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 &&
849 test_must_fail git bisect a &&
850 test_must_fail git bisect b &&
851 test_must_fail git bisect bad &&
852 test_must_fail git bisect good &&
853 test_must_fail git bisect new &&
854 test_must_fail git bisect old
855'
856
857test_expect_success 'bisect terms rejects invalid terms' '
858 git bisect reset &&
4d9005ff 859 test_must_fail git bisect start --term-good &&
06e6a745 860 test_must_fail git bisect start --term-good invalid..term &&
4d9005ff 861 test_must_fail git bisect start --term-bad &&
06e6a745
MM
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
868'
869
870test_expect_success 'bisect start --term-* does store terms' '
871 git bisect reset &&
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.
877 EOF
c9e6ce41 878 test_i18ncmp expected actual &&
06e6a745
MM
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
885'
886
887test_expect_success 'bisect start takes options and revs in any order' '
888 git bisect reset &&
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
895'
896
ba7eafe1
PB
897test_expect_success 'git bisect reset cleans bisection state properly' '
898 git bisect reset &&
899 git bisect start &&
900 git bisect good $HASH1 &&
901 git bisect bad $HASH4 &&
902 git bisect reset &&
903 test -z "$(git for-each-ref "refs/bisect/*")" &&
904 test_path_is_missing "$GIT_DIR/BISECT_EXPECTED_REV" &&
905 test_path_is_missing "$GIT_DIR/BISECT_ANCESTORS_OK" &&
906 test_path_is_missing "$GIT_DIR/BISECT_LOG" &&
907 test_path_is_missing "$GIT_DIR/BISECT_RUN" &&
908 test_path_is_missing "$GIT_DIR/BISECT_TERMS" &&
909 test_path_is_missing "$GIT_DIR/head-name" &&
910 test_path_is_missing "$GIT_DIR/BISECT_HEAD" &&
911 test_path_is_missing "$GIT_DIR/BISECT_START"
912'
913
a17c4101 914test_done