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