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