]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6030-bisect-porcelain.sh
path.c: don't call the match function without value in trie_find()
[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 &&
151 test_must_fail test -e .git/BISECT_START
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 &&
169 test_must_fail test -e .git/BISECT_START
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 &&
178 test_must_fail test -e .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
CC
245# We want to automatically find the commit that
246# introduced "Another" into hello.
247test_expect_success \
38a47fd6
CC
248 '"git bisect run" simple case' \
249 'echo "#"\!"/bin/sh" > test_script.sh &&
a17c4101
CC
250 echo "grep Another hello > /dev/null" >> test_script.sh &&
251 echo "test \$? -ne 0" >> test_script.sh &&
252 chmod +x test_script.sh &&
253 git bisect start &&
254 git bisect good $HASH1 &&
255 git bisect bad $HASH4 &&
256 git bisect run ./test_script.sh > my_bisect_log.txt &&
21d0bc2f 257 grep "$HASH3 is the first bad commit" my_bisect_log.txt &&
38a47fd6
CC
258 git bisect reset'
259
260# We want to automatically find the commit that
261# introduced "Ciao" into hello.
262test_expect_success \
263 '"git bisect run" with more complex "git bisect start"' \
264 'echo "#"\!"/bin/sh" > test_script.sh &&
265 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
266 echo "test \$? -ne 0" >> test_script.sh &&
267 chmod +x test_script.sh &&
268 git bisect start $HASH4 $HASH1 &&
269 git bisect run ./test_script.sh > my_bisect_log.txt &&
21d0bc2f 270 grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
38a47fd6 271 git bisect reset'
a17c4101 272
97e1c51e
CC
273# $HASH1 is good, $HASH5 is bad, we skip $HASH3
274# but $HASH4 is good,
275# so we should find $HASH5 as the first bad commit
276HASH5=
277test_expect_success 'bisect skip: add line and then a new test' '
278 add_line_into_file "5: Another new line." hello &&
279 HASH5=$(git rev-parse --verify HEAD) &&
280 git bisect start $HASH5 $HASH1 &&
281 git bisect skip &&
282 git bisect good > my_bisect_log.txt &&
21d0bc2f 283 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
fce0499f 284 git bisect log > log_to_replay.txt &&
37f9fd0d
CC
285 git bisect reset
286'
287
288test_expect_success 'bisect skip and bisect replay' '
289 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
21d0bc2f 290 grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
97e1c51e
CC
291 git bisect reset
292'
293
71b0251c
CC
294HASH6=
295test_expect_success 'bisect run & skip: cannot tell between 2' '
296 add_line_into_file "6: Yet a line." hello &&
297 HASH6=$(git rev-parse --verify HEAD) &&
298 echo "#"\!"/bin/sh" > test_script.sh &&
b4ce54fc 299 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
71b0251c
CC
300 echo "grep line hello > /dev/null" >> test_script.sh &&
301 echo "test \$? -ne 0" >> test_script.sh &&
302 chmod +x test_script.sh &&
303 git bisect start $HASH6 $HASH1 &&
304 if git bisect run ./test_script.sh > my_bisect_log.txt
305 then
306 echo Oops, should have failed.
307 false
308 else
309 test $? -eq 2 &&
310 grep "first bad commit could be any of" my_bisect_log.txt &&
311 ! grep $HASH3 my_bisect_log.txt &&
312 ! grep $HASH6 my_bisect_log.txt &&
313 grep $HASH4 my_bisect_log.txt &&
314 grep $HASH5 my_bisect_log.txt
315 fi
316'
317
318HASH7=
319test_expect_success 'bisect run & skip: find first bad' '
320 git bisect reset &&
321 add_line_into_file "7: Should be the last line." hello &&
322 HASH7=$(git rev-parse --verify HEAD) &&
323 echo "#"\!"/bin/sh" > test_script.sh &&
b4ce54fc
JK
324 echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
325 echo "sed -ne \\\$p hello | grep day > /dev/null && exit 125" >> test_script.sh &&
71b0251c
CC
326 echo "grep Yet hello > /dev/null" >> test_script.sh &&
327 echo "test \$? -ne 0" >> test_script.sh &&
328 chmod +x test_script.sh &&
329 git bisect start $HASH7 $HASH1 &&
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
JS
353 git bisect reset &&
354 git checkout master^ &&
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
461test_expect_success 'good merge bases when good and bad are siblings' '
462 git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt &&
14dc4899 463 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
f821d089 464 git bisect good > my_bisect_log2.txt &&
14dc4899 465 test_i18ngrep "merge base must be tested" my_bisect_log2.txt &&
f821d089
CC
466 {
467 {
468 grep "$SIDE_HASH5" my_bisect_log.txt &&
469 grep "$HASH5" my_bisect_log2.txt
470 } || {
471 grep "$SIDE_HASH5" my_bisect_log2.txt &&
472 grep "$HASH5" my_bisect_log.txt
473 }
474 } &&
475 git bisect reset
476'
477
c9c4e2d5 478test_expect_success 'optimized merge base checks' '
c9c4e2d5 479 git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
14dc4899 480 test_i18ngrep "merge base must be tested" my_bisect_log.txt &&
c9c4e2d5 481 grep "$HASH4" my_bisect_log.txt &&
c9c4e2d5
CC
482 git bisect good > my_bisect_log2.txt &&
483 test -f ".git/BISECT_ANCESTORS_OK" &&
484 test "$HASH6" = $(git rev-parse --verify HEAD) &&
c9c4e2d5 485 git bisect bad > my_bisect_log3.txt &&
c9c4e2d5 486 git bisect good "$A_HASH" > my_bisect_log4.txt &&
14dc4899 487 test_i18ngrep "merge base must be tested" my_bisect_log4.txt &&
2d938fc7 488 test_must_fail test -f ".git/BISECT_ANCESTORS_OK"
c9c4e2d5
CC
489'
490
b74d7efb
CC
491# This creates another side branch called "parallel" with some files
492# in some directories, to test bisecting with paths.
493#
494# We should have the following:
495#
496# P1-P2-P3-P4-P5-P6-P7
497# / / /
498# H1-H2-H3-H4-H5-H6-H7
499# \ \ \
500# S5-A \
501# \ \
502# S6-S7----B
503#
504test_expect_success '"parallel" side branch creation' '
505 git bisect reset &&
506 git checkout -b parallel $HASH1 &&
507 mkdir dir1 dir2 &&
508 add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 &&
509 PARA_HASH1=$(git rev-parse --verify HEAD) &&
510 add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
511 PARA_HASH2=$(git rev-parse --verify HEAD) &&
512 add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
a48fcd83 513 PARA_HASH3=$(git rev-parse --verify HEAD) &&
b74d7efb 514 git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
a48fcd83 515 PARA_HASH4=$(git rev-parse --verify HEAD) &&
b74d7efb 516 add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
a48fcd83 517 PARA_HASH5=$(git rev-parse --verify HEAD) &&
b74d7efb 518 add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
a48fcd83 519 PARA_HASH6=$(git rev-parse --verify HEAD) &&
b74d7efb
CC
520 git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
521 PARA_HASH7=$(git rev-parse --verify HEAD)
522'
523
524test_expect_success 'restricting bisection on one dir' '
525 git bisect reset &&
526 git bisect start HEAD $HASH1 -- dir1 &&
527 para1=$(git rev-parse --verify HEAD) &&
528 test "$para1" = "$PARA_HASH1" &&
529 git bisect bad > my_bisect_log.txt &&
21d0bc2f 530 grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
b74d7efb
CC
531'
532
533test_expect_success 'restricting bisection on one dir and a file' '
534 git bisect reset &&
535 git bisect start HEAD $HASH1 -- dir1 hello &&
536 para4=$(git rev-parse --verify HEAD) &&
537 test "$para4" = "$PARA_HASH4" &&
538 git bisect bad &&
539 hash3=$(git rev-parse --verify HEAD) &&
540 test "$hash3" = "$HASH3" &&
541 git bisect good &&
542 hash4=$(git rev-parse --verify HEAD) &&
543 test "$hash4" = "$HASH4" &&
544 git bisect good &&
545 para1=$(git rev-parse --verify HEAD) &&
546 test "$para1" = "$PARA_HASH1" &&
547 git bisect good > my_bisect_log.txt &&
21d0bc2f 548 grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
b74d7efb
CC
549'
550
a66037c9
CC
551test_expect_success 'skipping away from skipped commit' '
552 git bisect start $PARA_HASH7 $HASH1 &&
553 para4=$(git rev-parse --verify HEAD) &&
554 test "$para4" = "$PARA_HASH4" &&
555 git bisect skip &&
556 hash7=$(git rev-parse --verify HEAD) &&
557 test "$hash7" = "$HASH7" &&
558 git bisect skip &&
ebc9529f
CC
559 para3=$(git rev-parse --verify HEAD) &&
560 test "$para3" = "$PARA_HASH3"
a66037c9
CC
561'
562
8f69f72f
CC
563test_expect_success 'erroring out when using bad path parameters' '
564 test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
14dc4899 565 test_i18ngrep "bad path parameters" error.txt
8f69f72f
CC
566'
567
24c51280
JS
568test_expect_success 'test bisection on bare repo - --no-checkout specified' '
569 git clone --bare . bare.nocheckout &&
570 (
571 cd bare.nocheckout &&
572 git bisect start --no-checkout &&
573 git bisect good $HASH1 &&
574 git bisect bad $HASH4 &&
575 git bisect run eval \
576 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
e4e6e8b4 577 >../nocheckout.log
24c51280
JS
578 ) &&
579 grep "$HASH3 is the first bad commit" nocheckout.log
580'
581
582
583test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
584 git clone --bare . bare.defaulted &&
585 (
586 cd bare.defaulted &&
587 git bisect start &&
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 >../defaulted.log
24c51280
JS
593 ) &&
594 grep "$HASH3 is the first bad commit" defaulted.log
595'
596
a17c4101 597#
d3dfeedf
JS
598# This creates a broken branch which cannot be checked out because
599# the tree created has been deleted.
a17c4101 600#
d3dfeedf
JS
601# H1-H2-H3-H4-H5-H6-H7 <--other
602# \
603# S5-S6'-S7'-S8'-S9 <--broken
604#
605# Commits marked with ' have a missing tree.
606#
607test_expect_success 'broken branch creation' '
608 git bisect reset &&
609 git checkout -b broken $HASH4 &&
610 git tag BROKEN_HASH4 $HASH4 &&
611 add_line_into_file "5(broken): first line on a broken branch" hello2 &&
612 git tag BROKEN_HASH5 &&
613 mkdir missing &&
614 :> missing/MISSING &&
615 git add missing/MISSING &&
e4e6e8b4 616 git commit -m "6(broken): Added file that will be deleted" &&
d3dfeedf 617 git tag BROKEN_HASH6 &&
0795aed0 618 deleted=$(git rev-parse --verify HEAD:missing) &&
d3dfeedf
JS
619 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
620 git tag BROKEN_HASH7 &&
621 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
622 git tag BROKEN_HASH8 &&
623 git rm missing/MISSING &&
e4e6e8b4 624 git commit -m "9(broken): Remove missing file" &&
d3dfeedf 625 git tag BROKEN_HASH9 &&
0795aed0 626 rm .git/objects/$(test_oid_to_path $deleted)
d3dfeedf
JS
627'
628
629echo "" > expected.ok
630cat > expected.missing-tree.default <<EOF
0795aed0 631fatal: unable to read tree $deleted
d3dfeedf
JS
632EOF
633
634test_expect_success 'bisect fails if tree is broken on start commit' '
635 git bisect reset &&
636 test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
637 test_cmp expected.missing-tree.default error.txt
638'
639
640test_expect_success 'bisect fails if tree is broken on trial commit' '
641 git bisect reset &&
642 test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
643 git reset --hard broken &&
644 git checkout broken &&
645 test_cmp expected.missing-tree.default error.txt
646'
647
b704a8b3
JS
648check_same()
649{
650 echo "Checking $1 is the same as $2" &&
5d77298d 651 test_cmp_rev "$1" "$2"
b704a8b3
JS
652}
653
654test_expect_success 'bisect: --no-checkout - start commit bad' '
655 git bisect reset &&
656 git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
657 check_same BROKEN_HASH6 BISECT_HEAD &&
658 git bisect reset
659'
660
661test_expect_success 'bisect: --no-checkout - trial commit bad' '
662 git bisect reset &&
663 git bisect start broken BROKEN_HASH4 --no-checkout &&
664 check_same BROKEN_HASH6 BISECT_HEAD &&
665 git bisect reset
666'
667
668test_expect_success 'bisect: --no-checkout - target before breakage' '
669 git bisect reset &&
670 git bisect start broken BROKEN_HASH4 --no-checkout &&
671 check_same BROKEN_HASH6 BISECT_HEAD &&
672 git bisect bad BISECT_HEAD &&
673 check_same BROKEN_HASH5 BISECT_HEAD &&
674 git bisect bad BISECT_HEAD &&
675 check_same BROKEN_HASH5 bisect/bad &&
676 git bisect reset
677'
678
679test_expect_success 'bisect: --no-checkout - target in breakage' '
680 git bisect reset &&
681 git bisect start broken BROKEN_HASH4 --no-checkout &&
682 check_same BROKEN_HASH6 BISECT_HEAD &&
683 git bisect bad BISECT_HEAD &&
684 check_same BROKEN_HASH5 BISECT_HEAD &&
b02be8b9 685 test_must_fail git bisect good BISECT_HEAD &&
b704a8b3
JS
686 check_same BROKEN_HASH6 bisect/bad &&
687 git bisect reset
688'
689
690test_expect_success 'bisect: --no-checkout - target after breakage' '
691 git bisect reset &&
692 git bisect start broken BROKEN_HASH4 --no-checkout &&
693 check_same BROKEN_HASH6 BISECT_HEAD &&
694 git bisect good BISECT_HEAD &&
695 check_same BROKEN_HASH8 BISECT_HEAD &&
b02be8b9 696 test_must_fail git bisect good BISECT_HEAD &&
b704a8b3
JS
697 check_same BROKEN_HASH9 bisect/bad &&
698 git bisect reset
699'
700
701test_expect_success 'bisect: demonstrate identification of damage boundary' "
702 git bisect reset &&
703 git checkout broken &&
704 git bisect start broken master --no-checkout &&
b02be8b9 705 test_must_fail git bisect run \"\$SHELL_PATH\" -c '
b704a8b3
JS
706 GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
707 git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
708 git pack-objects --stdout >/dev/null < tmp.\$\$
709 rc=\$?
710 rm -f tmp.\$\$
711 test \$rc = 0' &&
712 check_same BROKEN_HASH6 bisect/bad &&
713 git bisect reset
714"
715
a7f8b8ac 716cat > expected.bisect-log <<EOF
0795aed0 717# bad: [$HASH4] Add <4: Ciao for now> into <hello>.
718# good: [$HASH2] Add <2: A new day for git> into <hello>.
719git bisect start '$HASH4' '$HASH2'
720# good: [$HASH3] Add <3: Another new day for git> into <hello>.
721git bisect good $HASH3
722# first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
a7f8b8ac
TH
723EOF
724
2e3a16b2 725test_expect_success 'bisect log: successful result' '
a7f8b8ac
TH
726 git bisect reset &&
727 git bisect start $HASH4 $HASH2 &&
728 git bisect good &&
729 git bisect log >bisect-log.txt &&
730 test_cmp expected.bisect-log bisect-log.txt &&
731 git bisect reset
732'
733
f989cac9 734cat > expected.bisect-skip-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# skip: [$HASH3] Add <3: Another new day for git> into <hello>.
739git bisect skip $HASH3
f989cac9 740# only skipped commits left to test
0795aed0 741# possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>.
742# possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>.
f989cac9
TH
743EOF
744
745test_expect_success 'bisect log: only skip commits left' '
746 git bisect reset &&
747 git bisect start $HASH4 $HASH2 &&
748 test_must_fail git bisect skip &&
749 git bisect log >bisect-skip-log.txt &&
750 test_cmp expected.bisect-skip-log bisect-skip-log.txt &&
751 git bisect reset
752'
753
07913d5a
CC
754test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' '
755 git checkout parallel &&
756 git bisect start HEAD $HASH1 &&
757 git bisect good HEAD &&
758 git bisect bad HEAD &&
759 test "$HASH6" = $(git rev-parse --verify HEAD) &&
760 git bisect reset
761'
762
21e5cfd8
AD
763test_expect_success 'bisect starts with only one new' '
764 git bisect reset &&
765 git bisect start &&
766 git bisect new $HASH4 &&
767 git bisect next
768'
769
770test_expect_success 'bisect does not start with only one old' '
771 git bisect reset &&
772 git bisect start &&
773 git bisect old $HASH1 &&
774 test_must_fail git bisect next
775'
776
777test_expect_success 'bisect start with one new and old' '
778 git bisect reset &&
779 git bisect start &&
780 git bisect old $HASH1 &&
781 git bisect new $HASH4 &&
782 git bisect new &&
783 git bisect new >bisect_result &&
784 grep "$HASH2 is the first new commit" bisect_result &&
785 git bisect log >log_to_replay.txt &&
786 git bisect reset
787'
788
789test_expect_success 'bisect replay with old and new' '
790 git bisect replay log_to_replay.txt >bisect_result &&
791 grep "$HASH2 is the first new commit" bisect_result &&
792 git bisect reset
793'
794
795test_expect_success 'bisect cannot mix old/new and good/bad' '
796 git bisect start &&
797 git bisect bad $HASH4 &&
798 test_must_fail git bisect old $HASH1
799'
800
21b55e33
MM
801test_expect_success 'bisect terms needs 0 or 1 argument' '
802 git bisect reset &&
803 test_must_fail git bisect terms only-one &&
804 test_must_fail git bisect terms 1 2 &&
805 test_must_fail git bisect terms 2>actual &&
450ebb73 806 echo "error: no terms defined" >expected &&
c9e6ce41 807 test_i18ncmp expected actual
21b55e33
MM
808'
809
810test_expect_success 'bisect terms shows good/bad after start' '
811 git bisect reset &&
812 git bisect start HEAD $HASH1 &&
813 git bisect terms --term-good >actual &&
814 echo good >expected &&
815 test_cmp expected actual &&
816 git bisect terms --term-bad >actual &&
817 echo bad >expected &&
818 test_cmp expected actual
819'
820
06e6a745
MM
821test_expect_success 'bisect start with one term1 and term2' '
822 git bisect reset &&
823 git bisect start --term-old term2 --term-new term1 &&
824 git bisect term2 $HASH1 &&
825 git bisect term1 $HASH4 &&
826 git bisect term1 &&
827 git bisect term1 >bisect_result &&
828 grep "$HASH2 is the first term1 commit" bisect_result &&
829 git bisect log >log_to_replay.txt &&
830 git bisect reset
831'
832
833test_expect_success 'bisect replay with term1 and term2' '
834 git bisect replay log_to_replay.txt >bisect_result &&
835 grep "$HASH2 is the first term1 commit" bisect_result &&
836 git bisect reset
837'
838
839test_expect_success 'bisect start term1 term2' '
840 git bisect reset &&
841 git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
842 git bisect term1 &&
843 git bisect term1 >bisect_result &&
844 grep "$HASH2 is the first term1 commit" bisect_result &&
845 git bisect log >log_to_replay.txt &&
846 git bisect reset
847'
848
849test_expect_success 'bisect cannot mix terms' '
850 git bisect reset &&
851 git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 &&
852 test_must_fail git bisect a &&
853 test_must_fail git bisect b &&
854 test_must_fail git bisect bad &&
855 test_must_fail git bisect good &&
856 test_must_fail git bisect new &&
857 test_must_fail git bisect old
858'
859
860test_expect_success 'bisect terms rejects invalid terms' '
861 git bisect reset &&
862 test_must_fail git bisect start --term-good invalid..term &&
863 test_must_fail git bisect terms --term-bad invalid..term &&
864 test_must_fail git bisect terms --term-good bad &&
865 test_must_fail git bisect terms --term-good old &&
866 test_must_fail git bisect terms --term-good skip &&
867 test_must_fail git bisect terms --term-good reset &&
868 test_path_is_missing .git/BISECT_TERMS
869'
870
871test_expect_success 'bisect start --term-* does store terms' '
872 git bisect reset &&
873 git bisect start --term-bad=one --term-good=two &&
874 git bisect terms >actual &&
875 cat <<-EOF >expected &&
876 Your current terms are two for the old state
877 and one for the new state.
878 EOF
c9e6ce41 879 test_i18ncmp expected actual &&
06e6a745
MM
880 git bisect terms --term-bad >actual &&
881 echo one >expected &&
882 test_cmp expected actual &&
883 git bisect terms --term-good >actual &&
884 echo two >expected &&
885 test_cmp expected actual
886'
887
888test_expect_success 'bisect start takes options and revs in any order' '
889 git bisect reset &&
890 git bisect start --term-good one $HASH4 \
891 --term-good two --term-bad bad-term \
892 $HASH1 --term-good three -- &&
893 (git bisect terms --term-bad && git bisect terms --term-good) >actual &&
894 printf "%s\n%s\n" bad-term three >expected &&
895 test_cmp expected actual
896'
897
ba7eafe1
PB
898test_expect_success 'git bisect reset cleans bisection state properly' '
899 git bisect reset &&
900 git bisect start &&
901 git bisect good $HASH1 &&
902 git bisect bad $HASH4 &&
903 git bisect reset &&
904 test -z "$(git for-each-ref "refs/bisect/*")" &&
905 test_path_is_missing "$GIT_DIR/BISECT_EXPECTED_REV" &&
906 test_path_is_missing "$GIT_DIR/BISECT_ANCESTORS_OK" &&
907 test_path_is_missing "$GIT_DIR/BISECT_LOG" &&
908 test_path_is_missing "$GIT_DIR/BISECT_RUN" &&
909 test_path_is_missing "$GIT_DIR/BISECT_TERMS" &&
910 test_path_is_missing "$GIT_DIR/head-name" &&
911 test_path_is_missing "$GIT_DIR/BISECT_HEAD" &&
912 test_path_is_missing "$GIT_DIR/BISECT_START"
913'
914
a17c4101 915test_done