]>
Commit | Line | Data |
---|---|---|
a17c4101 CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Christian Couder | |
4 | # | |
3604e7c5 | 5 | test_description='Tests git bisect functionality' |
a17c4101 | 6 | |
0a5280a9 JH |
7 | exec </dev/null |
8 | ||
1550bb6e | 9 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
10 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
11 | ||
a17c4101 CC |
12 | . ./test-lib.sh |
13 | ||
14 | add_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 | ||
32 | HASH1= | |
ab69e89c | 33 | HASH2= |
a17c4101 CC |
34 | HASH3= |
35 | HASH4= | |
36 | ||
ab69e89c JH |
37 | test_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 | 48 | test_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 | 55 | test_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 | ||
62 | test_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 | 70 | test_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 |
88 | test_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 | 95 | test_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 | ||
102 | test_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 | ||
114 | test_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 |
120 | test_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 |
132 | test_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 |
144 | test_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 |
156 | test_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 |
164 | test_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 | 173 | test_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 | 182 | test_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 | 196 | test_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 | |
208 | test_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 | |
224 | test_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 | |
240 | test_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 | ||
982fecf7 ÆAB |
255 | test_bisect_run_args () { |
256 | test_when_finished "rm -f run.sh actual" && | |
257 | >actual && | |
258 | cat >expect.args && | |
259 | cat <&6 >expect.out && | |
260 | cat <&7 >expect.err && | |
261 | write_script run.sh <<-\EOF && | |
262 | while test $# != 0 | |
263 | do | |
264 | echo "<$1>" && | |
265 | shift | |
266 | done >actual.args | |
267 | EOF | |
268 | ||
269 | test_when_finished "git bisect reset" && | |
270 | git bisect start && | |
271 | git bisect good $HASH1 && | |
272 | git bisect bad $HASH4 && | |
273 | git bisect run ./run.sh $@ >actual.out.raw 2>actual.err && | |
274 | # Prune just the log output | |
275 | sed -n \ | |
276 | -e '/^Author:/d' \ | |
277 | -e '/^Date:/d' \ | |
278 | -e '/^$/d' \ | |
279 | -e '/^commit /d' \ | |
280 | -e '/^ /d' \ | |
281 | -e 'p' \ | |
282 | <actual.out.raw >actual.out && | |
283 | test_cmp expect.out actual.out && | |
284 | test_cmp expect.err actual.err && | |
285 | test_cmp expect.args actual.args | |
286 | } | |
287 | ||
288 | test_expect_failure 'git bisect run: args, stdout and stderr with no arguments' " | |
289 | test_bisect_run_args <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' | |
290 | EOF_ARGS | |
291 | running ./run.sh | |
292 | $HASH4 is the first bad commit | |
293 | bisect run success | |
294 | EOF_OUT | |
295 | EOF_ERR | |
296 | " | |
297 | ||
298 | test_expect_failure 'git bisect run: args, stdout and stderr: "--" argument' " | |
299 | test_bisect_run_args -- <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' | |
300 | <--> | |
301 | EOF_ARGS | |
302 | running ./run.sh -- | |
303 | $HASH4 is the first bad commit | |
304 | bisect run success | |
305 | EOF_OUT | |
306 | EOF_ERR | |
307 | " | |
308 | ||
309 | test_expect_failure 'git bisect run: args, stdout and stderr: "--log foo --no-log bar" arguments' " | |
310 | test_bisect_run_args --log foo --no-log bar <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' | |
311 | <--log> | |
312 | <foo> | |
313 | <--no-log> | |
314 | <bar> | |
315 | EOF_ARGS | |
316 | running ./run.sh --log foo --no-log bar | |
317 | $HASH4 is the first bad commit | |
318 | bisect run success | |
319 | EOF_OUT | |
320 | EOF_ERR | |
321 | " | |
322 | ||
323 | test_expect_failure 'git bisect run: args, stdout and stderr: "--bisect-start" argument' " | |
324 | test_bisect_run_args --bisect-start <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR' | |
325 | <--bisect-start> | |
326 | EOF_ARGS | |
327 | running ./run.sh --bisect-start | |
328 | $HASH4 is the first bad commit | |
329 | bisect run success | |
330 | EOF_OUT | |
331 | EOF_ERR | |
332 | " | |
333 | ||
a17c4101 | 334 | # We want to automatically find the commit that |
15a4802a AL |
335 | # added "Another" into hello. |
336 | test_expect_success '"git bisect run" simple case' ' | |
337 | write_script test_script.sh <<-\EOF && | |
338 | ! grep Another hello >/dev/null | |
339 | EOF | |
340 | git bisect start && | |
341 | git bisect good $HASH1 && | |
342 | git bisect bad $HASH4 && | |
343 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
344 | grep "$HASH3 is the first bad commit" my_bisect_log.txt && | |
345 | git bisect reset | |
346 | ' | |
38a47fd6 | 347 | |
e9011b60 ĐTCD |
348 | # We want to make sure no arguments has been eaten |
349 | test_expect_success '"git bisect run" simple case' ' | |
350 | git bisect start && | |
351 | git bisect good $HASH1 && | |
352 | git bisect bad $HASH4 && | |
353 | git bisect run printf "%s %s\n" reset --bisect-skip >my_bisect_log.txt && | |
354 | grep -e "reset --bisect-skip" my_bisect_log.txt && | |
355 | git bisect reset | |
356 | ' | |
357 | ||
38a47fd6 | 358 | # We want to automatically find the commit that |
15a4802a AL |
359 | # added "Ciao" into hello. |
360 | test_expect_success '"git bisect run" with more complex "git bisect start"' ' | |
361 | write_script test_script.sh <<-\EOF && | |
362 | ! grep Ciao hello >/dev/null | |
363 | EOF | |
364 | git bisect start $HASH4 $HASH1 && | |
365 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
366 | grep "$HASH4 is the first bad commit" my_bisect_log.txt && | |
367 | git bisect reset | |
368 | ' | |
a17c4101 | 369 | |
ba5bb815 RS |
370 | test_expect_success 'bisect run accepts exit code 126 as bad' ' |
371 | test_when_finished "git bisect reset" && | |
372 | write_script test_script.sh <<-\EOF && | |
373 | ! grep Another hello || exit 126 >/dev/null | |
374 | EOF | |
375 | git bisect start && | |
376 | git bisect good $HASH1 && | |
377 | git bisect bad $HASH4 && | |
378 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
379 | grep "$HASH3 is the first bad commit" my_bisect_log.txt | |
380 | ' | |
381 | ||
48af1fde | 382 | test_expect_success POSIXPERM 'bisect run fails with non-executable test script' ' |
ba5bb815 RS |
383 | test_when_finished "git bisect reset" && |
384 | >not-executable.sh && | |
385 | chmod -x not-executable.sh && | |
386 | git bisect start && | |
387 | git bisect good $HASH1 && | |
388 | git bisect bad $HASH4 && | |
389 | test_must_fail git bisect run ./not-executable.sh >my_bisect_log.txt && | |
390 | ! grep "is the first bad commit" my_bisect_log.txt | |
391 | ' | |
392 | ||
393 | test_expect_success 'bisect run accepts exit code 127 as bad' ' | |
394 | test_when_finished "git bisect reset" && | |
395 | write_script test_script.sh <<-\EOF && | |
396 | ! grep Another hello || exit 127 >/dev/null | |
397 | EOF | |
398 | git bisect start && | |
399 | git bisect good $HASH1 && | |
400 | git bisect bad $HASH4 && | |
401 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
402 | grep "$HASH3 is the first bad commit" my_bisect_log.txt | |
403 | ' | |
404 | ||
48af1fde | 405 | test_expect_success 'bisect run fails with missing test script' ' |
ba5bb815 RS |
406 | test_when_finished "git bisect reset" && |
407 | rm -f does-not-exist.sh && | |
408 | git bisect start && | |
409 | git bisect good $HASH1 && | |
410 | git bisect bad $HASH4 && | |
411 | test_must_fail git bisect run ./does-not-exist.sh >my_bisect_log.txt && | |
412 | ! grep "is the first bad commit" my_bisect_log.txt | |
413 | ' | |
414 | ||
97e1c51e CC |
415 | # $HASH1 is good, $HASH5 is bad, we skip $HASH3 |
416 | # but $HASH4 is good, | |
417 | # so we should find $HASH5 as the first bad commit | |
418 | HASH5= | |
419 | test_expect_success 'bisect skip: add line and then a new test' ' | |
420 | add_line_into_file "5: Another new line." hello && | |
421 | HASH5=$(git rev-parse --verify HEAD) && | |
422 | git bisect start $HASH5 $HASH1 && | |
423 | git bisect skip && | |
424 | git bisect good > my_bisect_log.txt && | |
21d0bc2f | 425 | grep "$HASH5 is the first bad commit" my_bisect_log.txt && |
fce0499f | 426 | git bisect log > log_to_replay.txt && |
37f9fd0d CC |
427 | git bisect reset |
428 | ' | |
429 | ||
430 | test_expect_success 'bisect skip and bisect replay' ' | |
431 | git bisect replay log_to_replay.txt > my_bisect_log.txt && | |
21d0bc2f | 432 | grep "$HASH5 is the first bad commit" my_bisect_log.txt && |
97e1c51e CC |
433 | git bisect reset |
434 | ' | |
435 | ||
71b0251c CC |
436 | HASH6= |
437 | test_expect_success 'bisect run & skip: cannot tell between 2' ' | |
438 | add_line_into_file "6: Yet a line." hello && | |
439 | HASH6=$(git rev-parse --verify HEAD) && | |
15a4802a AL |
440 | write_script test_script.sh <<-\EOF && |
441 | sed -ne \$p hello | grep Ciao >/dev/null && exit 125 | |
442 | ! grep line hello >/dev/null | |
443 | EOF | |
71b0251c | 444 | git bisect start $HASH6 $HASH1 && |
15a4802a AL |
445 | test_expect_code 2 git bisect run ./test_script.sh >my_bisect_log.txt && |
446 | grep "first bad commit could be any of" my_bisect_log.txt && | |
447 | ! grep $HASH3 my_bisect_log.txt && | |
448 | ! grep $HASH6 my_bisect_log.txt && | |
449 | grep $HASH4 my_bisect_log.txt && | |
450 | grep $HASH5 my_bisect_log.txt | |
71b0251c CC |
451 | ' |
452 | ||
453 | HASH7= | |
454 | test_expect_success 'bisect run & skip: find first bad' ' | |
455 | git bisect reset && | |
456 | add_line_into_file "7: Should be the last line." hello && | |
457 | HASH7=$(git rev-parse --verify HEAD) && | |
15a4802a AL |
458 | write_script test_script.sh <<-\EOF && |
459 | sed -ne \$p hello | grep Ciao >/dev/null && exit 125 | |
460 | sed -ne \$p hello | grep day >/dev/null && exit 125 | |
461 | ! grep Yet hello >/dev/null | |
462 | EOF | |
71b0251c | 463 | git bisect start $HASH7 $HASH1 && |
15a4802a | 464 | git bisect run ./test_script.sh >my_bisect_log.txt && |
21d0bc2f | 465 | grep "$HASH6 is the first bad commit" my_bisect_log.txt |
71b0251c CC |
466 | ' |
467 | ||
1a66a489 CC |
468 | test_expect_success 'bisect skip only one range' ' |
469 | git bisect reset && | |
470 | git bisect start $HASH7 $HASH1 && | |
471 | git bisect skip $HASH1..$HASH5 && | |
472 | test "$HASH6" = "$(git rev-parse --verify HEAD)" && | |
473 | test_must_fail git bisect bad > my_bisect_log.txt && | |
474 | grep "first bad commit could be any of" my_bisect_log.txt | |
475 | ' | |
ce32660e | 476 | |
1a66a489 CC |
477 | test_expect_success 'bisect skip many ranges' ' |
478 | git bisect start $HASH7 $HASH1 && | |
479 | test "$HASH4" = "$(git rev-parse --verify HEAD)" && | |
480 | git bisect skip $HASH2 $HASH2.. ..$HASH5 && | |
481 | test "$HASH6" = "$(git rev-parse --verify HEAD)" && | |
482 | test_must_fail git bisect bad > my_bisect_log.txt && | |
483 | grep "first bad commit could be any of" my_bisect_log.txt | |
484 | ' | |
485 | ||
486 | test_expect_success 'bisect starting with a detached HEAD' ' | |
ce32660e | 487 | git bisect reset && |
1550bb6e | 488 | git checkout main^ && |
ce32660e JS |
489 | HEAD=$(git rev-parse --verify HEAD) && |
490 | git bisect start && | |
b577bb92 | 491 | test $HEAD = $(cat .git/BISECT_START) && |
ce32660e JS |
492 | git bisect reset && |
493 | test $HEAD = $(git rev-parse --verify HEAD) | |
ee831f7d GP |
494 | ' |
495 | ||
42ba5ee7 CC |
496 | test_expect_success 'bisect errors out if bad and good are mistaken' ' |
497 | git bisect reset && | |
498 | test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error && | |
14dc4899 | 499 | test_i18ngrep "mistook good and bad" rev_list_error && |
42ba5ee7 CC |
500 | git bisect reset |
501 | ' | |
502 | ||
634f2464 CC |
503 | test_expect_success 'bisect does not create a "bisect" branch' ' |
504 | git bisect reset && | |
505 | git bisect start $HASH7 $HASH1 && | |
506 | git branch bisect && | |
507 | rev_hash4=$(git rev-parse --verify HEAD) && | |
508 | test "$rev_hash4" = "$HASH4" && | |
509 | git branch -D bisect && | |
510 | git bisect good && | |
511 | git branch bisect && | |
512 | rev_hash6=$(git rev-parse --verify HEAD) && | |
513 | test "$rev_hash6" = "$HASH6" && | |
514 | git bisect good > my_bisect_log.txt && | |
21d0bc2f | 515 | grep "$HASH7 is the first bad commit" my_bisect_log.txt && |
634f2464 CC |
516 | git bisect reset && |
517 | rev_hash6=$(git rev-parse --verify bisect) && | |
518 | test "$rev_hash6" = "$HASH6" && | |
519 | git branch -D bisect | |
520 | ' | |
521 | ||
f821d089 CC |
522 | # This creates a "side" branch to test "siblings" cases. |
523 | # | |
524 | # H1-H2-H3-H4-H5-H6-H7 <--other | |
525 | # \ | |
526 | # S5-S6-S7 <--side | |
527 | # | |
528 | test_expect_success 'side branch creation' ' | |
529 | git bisect reset && | |
530 | git checkout -b side $HASH4 && | |
531 | add_line_into_file "5(side): first line on a side branch" hello2 && | |
532 | SIDE_HASH5=$(git rev-parse --verify HEAD) && | |
533 | add_line_into_file "6(side): second line on a side branch" hello2 && | |
534 | SIDE_HASH6=$(git rev-parse --verify HEAD) && | |
535 | add_line_into_file "7(side): third line on a side branch" hello2 && | |
536 | SIDE_HASH7=$(git rev-parse --verify HEAD) | |
537 | ' | |
538 | ||
539 | test_expect_success 'good merge base when good and bad are siblings' ' | |
540 | git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt && | |
14dc4899 | 541 | test_i18ngrep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
542 | grep $HASH4 my_bisect_log.txt && |
543 | git bisect good > my_bisect_log.txt && | |
c7cf9566 | 544 | ! grep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
545 | grep $HASH6 my_bisect_log.txt && |
546 | git bisect reset | |
547 | ' | |
548 | test_expect_success 'skipped merge base when good and bad are siblings' ' | |
549 | git bisect start "$SIDE_HASH7" "$HASH7" > my_bisect_log.txt && | |
14dc4899 | 550 | test_i18ngrep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
551 | grep $HASH4 my_bisect_log.txt && |
552 | git bisect skip > my_bisect_log.txt 2>&1 && | |
bd757c18 | 553 | grep "warning" my_bisect_log.txt && |
f821d089 CC |
554 | grep $SIDE_HASH6 my_bisect_log.txt && |
555 | git bisect reset | |
556 | ' | |
557 | ||
558 | test_expect_success 'bad merge base when good and bad are siblings' ' | |
559 | git bisect start "$HASH7" HEAD > my_bisect_log.txt && | |
14dc4899 | 560 | test_i18ngrep "merge base must be tested" my_bisect_log.txt && |
f821d089 CC |
561 | grep $HASH4 my_bisect_log.txt && |
562 | test_must_fail git bisect bad > my_bisect_log.txt 2>&1 && | |
14dc4899 VA |
563 | test_i18ngrep "merge base $HASH4 is bad" my_bisect_log.txt && |
564 | test_i18ngrep "fixed between $HASH4 and \[$SIDE_HASH7\]" my_bisect_log.txt && | |
f821d089 CC |
565 | git bisect reset |
566 | ' | |
567 | ||
568 | # This creates a few more commits (A and B) to test "siblings" cases | |
569 | # when a good and a bad rev have many merge bases. | |
570 | # | |
571 | # We should have the following: | |
572 | # | |
573 | # H1-H2-H3-H4-H5-H6-H7 | |
574 | # \ \ \ | |
575 | # S5-A \ | |
576 | # \ \ | |
577 | # S6-S7----B | |
578 | # | |
579 | # And there A and B have 2 merge bases (S5 and H5) that should be | |
580 | # reported by "git merge-base --all A B". | |
581 | # | |
582 | test_expect_success 'many merge bases creation' ' | |
583 | git checkout "$SIDE_HASH5" && | |
584 | git merge -m "merge HASH5 and SIDE_HASH5" "$HASH5" && | |
585 | A_HASH=$(git rev-parse --verify HEAD) && | |
586 | git checkout side && | |
587 | git merge -m "merge HASH7 and SIDE_HASH7" "$HASH7" && | |
588 | B_HASH=$(git rev-parse --verify HEAD) && | |
589 | git merge-base --all "$A_HASH" "$B_HASH" > merge_bases.txt && | |
3fb0459b | 590 | test_line_count = 2 merge_bases.txt && |
f821d089 CC |
591 | grep "$HASH5" merge_bases.txt && |
592 | grep "$SIDE_HASH5" merge_bases.txt | |
593 | ' | |
594 | ||
e8861ffc AL |
595 | # We want to automatically find the merge that |
596 | # added "line" into hello. | |
597 | test_expect_success '"git bisect run --first-parent" simple case' ' | |
598 | git rev-list --first-parent $B_HASH ^$HASH4 >first_parent_chain.txt && | |
599 | write_script test_script.sh <<-\EOF && | |
600 | grep $(git rev-parse HEAD) first_parent_chain.txt || exit -1 | |
601 | ! grep line hello >/dev/null | |
602 | EOF | |
603 | git bisect start --first-parent && | |
604 | test_path_is_file ".git/BISECT_FIRST_PARENT" && | |
605 | git bisect good $HASH4 && | |
606 | git bisect bad $B_HASH && | |
607 | git bisect run ./test_script.sh >my_bisect_log.txt && | |
608 | grep "$B_HASH is the first bad commit" my_bisect_log.txt && | |
609 | git bisect reset && | |
610 | test_path_is_missing .git/BISECT_FIRST_PARENT | |
611 | ' | |
612 | ||
f821d089 CC |
613 | test_expect_success 'good merge bases when good and bad are siblings' ' |
614 | git bisect start "$B_HASH" "$A_HASH" > my_bisect_log.txt && | |
14dc4899 | 615 | test_i18ngrep "merge base must be tested" my_bisect_log.txt && |
f821d089 | 616 | git bisect good > my_bisect_log2.txt && |
14dc4899 | 617 | test_i18ngrep "merge base must be tested" my_bisect_log2.txt && |
f821d089 CC |
618 | { |
619 | { | |
620 | grep "$SIDE_HASH5" my_bisect_log.txt && | |
621 | grep "$HASH5" my_bisect_log2.txt | |
622 | } || { | |
623 | grep "$SIDE_HASH5" my_bisect_log2.txt && | |
624 | grep "$HASH5" my_bisect_log.txt | |
625 | } | |
626 | } && | |
627 | git bisect reset | |
628 | ' | |
629 | ||
c9c4e2d5 | 630 | test_expect_success 'optimized merge base checks' ' |
c9c4e2d5 | 631 | git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt && |
14dc4899 | 632 | test_i18ngrep "merge base must be tested" my_bisect_log.txt && |
c9c4e2d5 | 633 | grep "$HASH4" my_bisect_log.txt && |
c9c4e2d5 CC |
634 | git bisect good > my_bisect_log2.txt && |
635 | test -f ".git/BISECT_ANCESTORS_OK" && | |
636 | test "$HASH6" = $(git rev-parse --verify HEAD) && | |
675ef6ba | 637 | git bisect bad && |
c9c4e2d5 | 638 | git bisect good "$A_HASH" > my_bisect_log4.txt && |
14dc4899 | 639 | test_i18ngrep "merge base must be tested" my_bisect_log4.txt && |
085ba9b5 | 640 | test_path_is_missing ".git/BISECT_ANCESTORS_OK" |
c9c4e2d5 CC |
641 | ' |
642 | ||
b74d7efb CC |
643 | # This creates another side branch called "parallel" with some files |
644 | # in some directories, to test bisecting with paths. | |
645 | # | |
646 | # We should have the following: | |
647 | # | |
648 | # P1-P2-P3-P4-P5-P6-P7 | |
649 | # / / / | |
650 | # H1-H2-H3-H4-H5-H6-H7 | |
651 | # \ \ \ | |
652 | # S5-A \ | |
653 | # \ \ | |
654 | # S6-S7----B | |
655 | # | |
656 | test_expect_success '"parallel" side branch creation' ' | |
657 | git bisect reset && | |
658 | git checkout -b parallel $HASH1 && | |
659 | mkdir dir1 dir2 && | |
660 | add_line_into_file "1(para): line 1 on parallel branch" dir1/file1 && | |
661 | PARA_HASH1=$(git rev-parse --verify HEAD) && | |
662 | add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 && | |
663 | PARA_HASH2=$(git rev-parse --verify HEAD) && | |
664 | add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 && | |
a48fcd83 | 665 | PARA_HASH3=$(git rev-parse --verify HEAD) && |
b74d7efb | 666 | git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" && |
a48fcd83 | 667 | PARA_HASH4=$(git rev-parse --verify HEAD) && |
b74d7efb | 668 | add_line_into_file "5(para): add line on parallel branch" dir1/file1 && |
a48fcd83 | 669 | PARA_HASH5=$(git rev-parse --verify HEAD) && |
b74d7efb | 670 | add_line_into_file "6(para): add line on parallel branch" dir2/file2 && |
a48fcd83 | 671 | PARA_HASH6=$(git rev-parse --verify HEAD) && |
b74d7efb CC |
672 | git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" && |
673 | PARA_HASH7=$(git rev-parse --verify HEAD) | |
674 | ' | |
675 | ||
676 | test_expect_success 'restricting bisection on one dir' ' | |
677 | git bisect reset && | |
678 | git bisect start HEAD $HASH1 -- dir1 && | |
679 | para1=$(git rev-parse --verify HEAD) && | |
680 | test "$para1" = "$PARA_HASH1" && | |
681 | git bisect bad > my_bisect_log.txt && | |
21d0bc2f | 682 | grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt |
b74d7efb CC |
683 | ' |
684 | ||
685 | test_expect_success 'restricting bisection on one dir and a file' ' | |
686 | git bisect reset && | |
687 | git bisect start HEAD $HASH1 -- dir1 hello && | |
688 | para4=$(git rev-parse --verify HEAD) && | |
689 | test "$para4" = "$PARA_HASH4" && | |
690 | git bisect bad && | |
691 | hash3=$(git rev-parse --verify HEAD) && | |
692 | test "$hash3" = "$HASH3" && | |
693 | git bisect good && | |
694 | hash4=$(git rev-parse --verify HEAD) && | |
695 | test "$hash4" = "$HASH4" && | |
696 | git bisect good && | |
697 | para1=$(git rev-parse --verify HEAD) && | |
698 | test "$para1" = "$PARA_HASH1" && | |
699 | git bisect good > my_bisect_log.txt && | |
21d0bc2f | 700 | grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt |
b74d7efb CC |
701 | ' |
702 | ||
a66037c9 CC |
703 | test_expect_success 'skipping away from skipped commit' ' |
704 | git bisect start $PARA_HASH7 $HASH1 && | |
705 | para4=$(git rev-parse --verify HEAD) && | |
706 | test "$para4" = "$PARA_HASH4" && | |
707 | git bisect skip && | |
708 | hash7=$(git rev-parse --verify HEAD) && | |
709 | test "$hash7" = "$HASH7" && | |
710 | git bisect skip && | |
ebc9529f CC |
711 | para3=$(git rev-parse --verify HEAD) && |
712 | test "$para3" = "$PARA_HASH3" | |
a66037c9 CC |
713 | ' |
714 | ||
b8657347 | 715 | test_expect_success 'erroring out when using bad path arguments' ' |
8f69f72f | 716 | test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt && |
b8657347 | 717 | test_i18ngrep "bad path arguments" error.txt |
8f69f72f CC |
718 | ' |
719 | ||
24c51280 JS |
720 | test_expect_success 'test bisection on bare repo - --no-checkout specified' ' |
721 | git clone --bare . bare.nocheckout && | |
722 | ( | |
723 | cd bare.nocheckout && | |
724 | git bisect start --no-checkout && | |
725 | git bisect good $HASH1 && | |
726 | git bisect bad $HASH4 && | |
727 | git bisect run eval \ | |
728 | "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \ | |
e4e6e8b4 | 729 | >../nocheckout.log |
24c51280 JS |
730 | ) && |
731 | grep "$HASH3 is the first bad commit" nocheckout.log | |
732 | ' | |
733 | ||
734 | ||
735 | test_expect_success 'test bisection on bare repo - --no-checkout defaulted' ' | |
736 | git clone --bare . bare.defaulted && | |
737 | ( | |
738 | cd bare.defaulted && | |
739 | git bisect start && | |
740 | git bisect good $HASH1 && | |
741 | git bisect bad $HASH4 && | |
742 | git bisect run eval \ | |
743 | "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \ | |
e4e6e8b4 | 744 | >../defaulted.log |
24c51280 JS |
745 | ) && |
746 | grep "$HASH3 is the first bad commit" defaulted.log | |
747 | ' | |
748 | ||
a17c4101 | 749 | # |
d3dfeedf JS |
750 | # This creates a broken branch which cannot be checked out because |
751 | # the tree created has been deleted. | |
a17c4101 | 752 | # |
d3dfeedf JS |
753 | # H1-H2-H3-H4-H5-H6-H7 <--other |
754 | # \ | |
755 | # S5-S6'-S7'-S8'-S9 <--broken | |
756 | # | |
757 | # Commits marked with ' have a missing tree. | |
758 | # | |
759 | test_expect_success 'broken branch creation' ' | |
760 | git bisect reset && | |
761 | git checkout -b broken $HASH4 && | |
762 | git tag BROKEN_HASH4 $HASH4 && | |
763 | add_line_into_file "5(broken): first line on a broken branch" hello2 && | |
764 | git tag BROKEN_HASH5 && | |
765 | mkdir missing && | |
766 | :> missing/MISSING && | |
767 | git add missing/MISSING && | |
e4e6e8b4 | 768 | git commit -m "6(broken): Added file that will be deleted" && |
d3dfeedf | 769 | git tag BROKEN_HASH6 && |
0795aed0 | 770 | deleted=$(git rev-parse --verify HEAD:missing) && |
d3dfeedf JS |
771 | add_line_into_file "7(broken): second line on a broken branch" hello2 && |
772 | git tag BROKEN_HASH7 && | |
773 | add_line_into_file "8(broken): third line on a broken branch" hello2 && | |
774 | git tag BROKEN_HASH8 && | |
775 | git rm missing/MISSING && | |
e4e6e8b4 | 776 | git commit -m "9(broken): Remove missing file" && |
d3dfeedf | 777 | git tag BROKEN_HASH9 && |
0795aed0 | 778 | rm .git/objects/$(test_oid_to_path $deleted) |
d3dfeedf JS |
779 | ' |
780 | ||
781 | echo "" > expected.ok | |
782 | cat > expected.missing-tree.default <<EOF | |
0795aed0 | 783 | fatal: unable to read tree $deleted |
d3dfeedf JS |
784 | EOF |
785 | ||
786 | test_expect_success 'bisect fails if tree is broken on start commit' ' | |
787 | git bisect reset && | |
788 | test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt && | |
789 | test_cmp expected.missing-tree.default error.txt | |
790 | ' | |
791 | ||
792 | test_expect_success 'bisect fails if tree is broken on trial commit' ' | |
793 | git bisect reset && | |
794 | test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt && | |
795 | git reset --hard broken && | |
796 | git checkout broken && | |
797 | test_cmp expected.missing-tree.default error.txt | |
798 | ' | |
799 | ||
b704a8b3 JS |
800 | check_same() |
801 | { | |
802 | echo "Checking $1 is the same as $2" && | |
5d77298d | 803 | test_cmp_rev "$1" "$2" |
b704a8b3 JS |
804 | } |
805 | ||
806 | test_expect_success 'bisect: --no-checkout - start commit bad' ' | |
807 | git bisect reset && | |
808 | git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout && | |
809 | check_same BROKEN_HASH6 BISECT_HEAD && | |
810 | git bisect reset | |
811 | ' | |
812 | ||
813 | test_expect_success 'bisect: --no-checkout - trial commit bad' ' | |
814 | git bisect reset && | |
815 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
816 | check_same BROKEN_HASH6 BISECT_HEAD && | |
817 | git bisect reset | |
818 | ' | |
819 | ||
820 | test_expect_success 'bisect: --no-checkout - target before breakage' ' | |
821 | git bisect reset && | |
822 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
823 | check_same BROKEN_HASH6 BISECT_HEAD && | |
824 | git bisect bad BISECT_HEAD && | |
825 | check_same BROKEN_HASH5 BISECT_HEAD && | |
826 | git bisect bad BISECT_HEAD && | |
827 | check_same BROKEN_HASH5 bisect/bad && | |
828 | git bisect reset | |
829 | ' | |
830 | ||
831 | test_expect_success 'bisect: --no-checkout - target in breakage' ' | |
832 | git bisect reset && | |
833 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
834 | check_same BROKEN_HASH6 BISECT_HEAD && | |
835 | git bisect bad BISECT_HEAD && | |
836 | check_same BROKEN_HASH5 BISECT_HEAD && | |
b02be8b9 | 837 | test_must_fail git bisect good BISECT_HEAD && |
b704a8b3 JS |
838 | check_same BROKEN_HASH6 bisect/bad && |
839 | git bisect reset | |
840 | ' | |
841 | ||
842 | test_expect_success 'bisect: --no-checkout - target after breakage' ' | |
843 | git bisect reset && | |
844 | git bisect start broken BROKEN_HASH4 --no-checkout && | |
845 | check_same BROKEN_HASH6 BISECT_HEAD && | |
846 | git bisect good BISECT_HEAD && | |
847 | check_same BROKEN_HASH8 BISECT_HEAD && | |
b02be8b9 | 848 | test_must_fail git bisect good BISECT_HEAD && |
b704a8b3 JS |
849 | check_same BROKEN_HASH9 bisect/bad && |
850 | git bisect reset | |
851 | ' | |
852 | ||
853 | test_expect_success 'bisect: demonstrate identification of damage boundary' " | |
854 | git bisect reset && | |
855 | git checkout broken && | |
1550bb6e | 856 | git bisect start broken main --no-checkout && |
b02be8b9 | 857 | test_must_fail git bisect run \"\$SHELL_PATH\" -c ' |
b704a8b3 JS |
858 | GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) && |
859 | git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ && | |
860 | git pack-objects --stdout >/dev/null < tmp.\$\$ | |
861 | rc=\$? | |
862 | rm -f tmp.\$\$ | |
863 | test \$rc = 0' && | |
864 | check_same BROKEN_HASH6 bisect/bad && | |
865 | git bisect reset | |
866 | " | |
867 | ||
a7f8b8ac | 868 | cat > expected.bisect-log <<EOF |
0795aed0 | 869 | # bad: [$HASH4] Add <4: Ciao for now> into <hello>. |
870 | # good: [$HASH2] Add <2: A new day for git> into <hello>. | |
871 | git bisect start '$HASH4' '$HASH2' | |
872 | # good: [$HASH3] Add <3: Another new day for git> into <hello>. | |
873 | git bisect good $HASH3 | |
874 | # first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>. | |
a7f8b8ac TH |
875 | EOF |
876 | ||
2e3a16b2 | 877 | test_expect_success 'bisect log: successful result' ' |
a7f8b8ac TH |
878 | git bisect reset && |
879 | git bisect start $HASH4 $HASH2 && | |
880 | git bisect good && | |
881 | git bisect log >bisect-log.txt && | |
882 | test_cmp expected.bisect-log bisect-log.txt && | |
883 | git bisect reset | |
884 | ' | |
885 | ||
f989cac9 | 886 | cat > expected.bisect-skip-log <<EOF |
0795aed0 | 887 | # bad: [$HASH4] Add <4: Ciao for now> into <hello>. |
888 | # good: [$HASH2] Add <2: A new day for git> into <hello>. | |
889 | git bisect start '$HASH4' '$HASH2' | |
890 | # skip: [$HASH3] Add <3: Another new day for git> into <hello>. | |
891 | git bisect skip $HASH3 | |
f989cac9 | 892 | # only skipped commits left to test |
0795aed0 | 893 | # possible first bad commit: [$HASH4] Add <4: Ciao for now> into <hello>. |
894 | # possible first bad commit: [$HASH3] Add <3: Another new day for git> into <hello>. | |
f989cac9 TH |
895 | EOF |
896 | ||
897 | test_expect_success 'bisect log: only skip commits left' ' | |
898 | git bisect reset && | |
899 | git bisect start $HASH4 $HASH2 && | |
900 | test_must_fail git bisect skip && | |
901 | git bisect log >bisect-skip-log.txt && | |
902 | test_cmp expected.bisect-skip-log bisect-skip-log.txt && | |
903 | git bisect reset | |
904 | ' | |
905 | ||
07913d5a CC |
906 | test_expect_success '"git bisect bad HEAD" behaves as "git bisect bad"' ' |
907 | git checkout parallel && | |
908 | git bisect start HEAD $HASH1 && | |
909 | git bisect good HEAD && | |
910 | git bisect bad HEAD && | |
911 | test "$HASH6" = $(git rev-parse --verify HEAD) && | |
912 | git bisect reset | |
913 | ' | |
914 | ||
21e5cfd8 AD |
915 | test_expect_success 'bisect starts with only one new' ' |
916 | git bisect reset && | |
917 | git bisect start && | |
918 | git bisect new $HASH4 && | |
919 | git bisect next | |
920 | ' | |
921 | ||
922 | test_expect_success 'bisect does not start with only one old' ' | |
923 | git bisect reset && | |
924 | git bisect start && | |
925 | git bisect old $HASH1 && | |
926 | test_must_fail git bisect next | |
927 | ' | |
928 | ||
929 | test_expect_success 'bisect start with one new and old' ' | |
930 | git bisect reset && | |
931 | git bisect start && | |
932 | git bisect old $HASH1 && | |
933 | git bisect new $HASH4 && | |
934 | git bisect new && | |
935 | git bisect new >bisect_result && | |
936 | grep "$HASH2 is the first new commit" bisect_result && | |
937 | git bisect log >log_to_replay.txt && | |
938 | git bisect reset | |
939 | ' | |
940 | ||
941 | test_expect_success 'bisect replay with old and new' ' | |
942 | git bisect replay log_to_replay.txt >bisect_result && | |
943 | grep "$HASH2 is the first new commit" bisect_result && | |
944 | git bisect reset | |
945 | ' | |
946 | ||
6c722cbe CW |
947 | test_expect_success 'bisect replay with CRLF log' ' |
948 | append_cr <log_to_replay.txt >log_to_replay_crlf.txt && | |
949 | git bisect replay log_to_replay_crlf.txt >bisect_result_crlf && | |
950 | grep "$HASH2 is the first new commit" bisect_result_crlf && | |
951 | git bisect reset | |
952 | ' | |
953 | ||
21e5cfd8 AD |
954 | test_expect_success 'bisect cannot mix old/new and good/bad' ' |
955 | git bisect start && | |
956 | git bisect bad $HASH4 && | |
957 | test_must_fail git bisect old $HASH1 | |
958 | ' | |
959 | ||
21b55e33 MM |
960 | test_expect_success 'bisect terms needs 0 or 1 argument' ' |
961 | git bisect reset && | |
962 | test_must_fail git bisect terms only-one && | |
963 | test_must_fail git bisect terms 1 2 && | |
964 | test_must_fail git bisect terms 2>actual && | |
450ebb73 | 965 | echo "error: no terms defined" >expected && |
1108cea7 | 966 | test_cmp expected actual |
21b55e33 MM |
967 | ' |
968 | ||
969 | test_expect_success 'bisect terms shows good/bad after start' ' | |
970 | git bisect reset && | |
971 | git bisect start HEAD $HASH1 && | |
972 | git bisect terms --term-good >actual && | |
973 | echo good >expected && | |
974 | test_cmp expected actual && | |
975 | git bisect terms --term-bad >actual && | |
976 | echo bad >expected && | |
977 | test_cmp expected actual | |
978 | ' | |
979 | ||
06e6a745 MM |
980 | test_expect_success 'bisect start with one term1 and term2' ' |
981 | git bisect reset && | |
982 | git bisect start --term-old term2 --term-new term1 && | |
983 | git bisect term2 $HASH1 && | |
984 | git bisect term1 $HASH4 && | |
985 | git bisect term1 && | |
986 | git bisect term1 >bisect_result && | |
987 | grep "$HASH2 is the first term1 commit" bisect_result && | |
988 | git bisect log >log_to_replay.txt && | |
989 | git bisect reset | |
990 | ' | |
991 | ||
992 | test_expect_success 'bisect replay with term1 and term2' ' | |
993 | git bisect replay log_to_replay.txt >bisect_result && | |
994 | grep "$HASH2 is the first term1 commit" bisect_result && | |
995 | git bisect reset | |
996 | ' | |
997 | ||
998 | test_expect_success 'bisect start term1 term2' ' | |
999 | git bisect reset && | |
1000 | git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 && | |
1001 | git bisect term1 && | |
1002 | git bisect term1 >bisect_result && | |
1003 | grep "$HASH2 is the first term1 commit" bisect_result && | |
1004 | git bisect log >log_to_replay.txt && | |
1005 | git bisect reset | |
1006 | ' | |
1007 | ||
1008 | test_expect_success 'bisect cannot mix terms' ' | |
1009 | git bisect reset && | |
1010 | git bisect start --term-good term1 --term-bad term2 $HASH4 $HASH1 && | |
1011 | test_must_fail git bisect a && | |
1012 | test_must_fail git bisect b && | |
1013 | test_must_fail git bisect bad && | |
1014 | test_must_fail git bisect good && | |
1015 | test_must_fail git bisect new && | |
1016 | test_must_fail git bisect old | |
1017 | ' | |
1018 | ||
1019 | test_expect_success 'bisect terms rejects invalid terms' ' | |
1020 | git bisect reset && | |
4d9005ff | 1021 | test_must_fail git bisect start --term-good && |
06e6a745 | 1022 | test_must_fail git bisect start --term-good invalid..term && |
4d9005ff | 1023 | test_must_fail git bisect start --term-bad && |
06e6a745 MM |
1024 | test_must_fail git bisect terms --term-bad invalid..term && |
1025 | test_must_fail git bisect terms --term-good bad && | |
1026 | test_must_fail git bisect terms --term-good old && | |
1027 | test_must_fail git bisect terms --term-good skip && | |
1028 | test_must_fail git bisect terms --term-good reset && | |
1029 | test_path_is_missing .git/BISECT_TERMS | |
1030 | ' | |
1031 | ||
1032 | test_expect_success 'bisect start --term-* does store terms' ' | |
1033 | git bisect reset && | |
1034 | git bisect start --term-bad=one --term-good=two && | |
1035 | git bisect terms >actual && | |
1036 | cat <<-EOF >expected && | |
1037 | Your current terms are two for the old state | |
1038 | and one for the new state. | |
1039 | EOF | |
1108cea7 | 1040 | test_cmp expected actual && |
06e6a745 MM |
1041 | git bisect terms --term-bad >actual && |
1042 | echo one >expected && | |
1043 | test_cmp expected actual && | |
1044 | git bisect terms --term-good >actual && | |
1045 | echo two >expected && | |
1046 | test_cmp expected actual | |
1047 | ' | |
1048 | ||
1049 | test_expect_success 'bisect start takes options and revs in any order' ' | |
1050 | git bisect reset && | |
1051 | git bisect start --term-good one $HASH4 \ | |
1052 | --term-good two --term-bad bad-term \ | |
1053 | $HASH1 --term-good three -- && | |
1054 | (git bisect terms --term-bad && git bisect terms --term-good) >actual && | |
1055 | printf "%s\n%s\n" bad-term three >expected && | |
1056 | test_cmp expected actual | |
1057 | ' | |
1058 | ||
4cd66e7d RJ |
1059 | # Bisect is started with --term-new and --term-old arguments, |
1060 | # then skip. The HEAD should be changed. | |
1061 | test_expect_success 'bisect skip works with --term*' ' | |
1062 | git bisect reset && | |
1063 | git bisect start --term-new=fixed --term-old=unfixed HEAD $HASH1 && | |
1064 | hash_skipped_from=$(git rev-parse --verify HEAD) && | |
1065 | git bisect skip && | |
1066 | hash_skipped_to=$(git rev-parse --verify HEAD) && | |
1067 | test "$hash_skipped_from" != "$hash_skipped_to" | |
1068 | ' | |
1069 | ||
ba7eafe1 PB |
1070 | test_expect_success 'git bisect reset cleans bisection state properly' ' |
1071 | git bisect reset && | |
1072 | git bisect start && | |
1073 | git bisect good $HASH1 && | |
1074 | git bisect bad $HASH4 && | |
1075 | git bisect reset && | |
1076 | test -z "$(git for-each-ref "refs/bisect/*")" && | |
33fc5625 FC |
1077 | test_path_is_missing ".git/BISECT_EXPECTED_REV" && |
1078 | test_path_is_missing ".git/BISECT_ANCESTORS_OK" && | |
1079 | test_path_is_missing ".git/BISECT_LOG" && | |
1080 | test_path_is_missing ".git/BISECT_RUN" && | |
1081 | test_path_is_missing ".git/BISECT_TERMS" && | |
1082 | test_path_is_missing ".git/head-name" && | |
1083 | test_path_is_missing ".git/BISECT_HEAD" && | |
1084 | test_path_is_missing ".git/BISECT_START" | |
ba7eafe1 PB |
1085 | ' |
1086 | ||
7730f855 JK |
1087 | test_expect_success 'bisect handles annotated tags' ' |
1088 | test_commit commit-one && | |
1089 | git tag -m foo tag-one && | |
1090 | test_commit commit-two && | |
1091 | git tag -m foo tag-two && | |
1092 | git bisect start && | |
1093 | git bisect good tag-one && | |
1094 | git bisect bad tag-two >output && | |
1095 | bad=$(git rev-parse --verify tag-two^{commit}) && | |
1096 | grep "$bad is the first bad commit" output | |
1097 | ' | |
1098 | ||
282073cc MR |
1099 | test_expect_success 'bisect run fails with exit code equals or greater than 128' ' |
1100 | write_script test_script.sh <<-\EOF && | |
1101 | exit 128 | |
1102 | EOF | |
1103 | test_must_fail git bisect run ./test_script.sh && | |
1104 | write_script test_script.sh <<-\EOF && | |
1105 | exit 255 | |
1106 | EOF | |
1107 | test_must_fail git bisect run ./test_script.sh | |
1108 | ' | |
1109 | ||
5fe973b9 MR |
1110 | test_expect_success 'bisect visualize with a filename with dash and space' ' |
1111 | echo "My test line" >>"./-hello 2" && | |
1112 | git add -- "./-hello 2" && | |
1113 | git commit --quiet -m "Add test line" -- "./-hello 2" && | |
1114 | git bisect visualize -p -- "-hello 2" | |
1115 | ' | |
1116 | ||
0cf1defa CD |
1117 | test_expect_success 'bisect state output with multiple good commits' ' |
1118 | git bisect reset && | |
1119 | git bisect start >output && | |
1120 | grep "waiting for both good and bad commits" output && | |
f11046e6 CD |
1121 | git bisect log >output && |
1122 | grep "waiting for both good and bad commits" output && | |
0cf1defa CD |
1123 | git bisect good "$HASH1" >output && |
1124 | grep "waiting for bad commit, 1 good commit known" output && | |
f11046e6 CD |
1125 | git bisect log >output && |
1126 | grep "waiting for bad commit, 1 good commit known" output && | |
0cf1defa | 1127 | git bisect good "$HASH2" >output && |
f11046e6 CD |
1128 | grep "waiting for bad commit, 2 good commits known" output && |
1129 | git bisect log >output && | |
0cf1defa CD |
1130 | grep "waiting for bad commit, 2 good commits known" output |
1131 | ' | |
1132 | ||
1133 | test_expect_success 'bisect state output with bad commit' ' | |
1134 | git bisect reset && | |
1135 | git bisect start >output && | |
1136 | grep "waiting for both good and bad commits" output && | |
f11046e6 CD |
1137 | git bisect log >output && |
1138 | grep "waiting for both good and bad commits" output && | |
0cf1defa | 1139 | git bisect bad "$HASH4" >output && |
f11046e6 CD |
1140 | grep -F "waiting for good commit(s), bad commit known" output && |
1141 | git bisect log >output && | |
0cf1defa CD |
1142 | grep -F "waiting for good commit(s), bad commit known" output |
1143 | ' | |
1144 | ||
a17c4101 | 1145 | test_done |