@matheusbsbs / matheus-bagliano / commits / 71b0251cdd
Fork 0

Bisect run: "skip" current commit if script exit code is 125.

This is incompatible with previous versions because an exit code of 125 used to mark current commit as "bad". But hopefully this exit code is not much used by test scripts or other programs. (126 and 127 are used by POSIX compliant shells to mean "found but not executable" and "command not found", respectively.) Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Oct 26, 2007 at 05:39 UTC 71b0251cdd2cc35a983e21d4e71285db56d2a519
3 files changed +57 -4
Documentation/git-bisect.txt
+7 -3
@@ -182,14 +182,18 @@ $ git bisect run my_script
182 ------------
183
184 Note that the "run" script (`my_script` in the above example) should
185 -exit with code 0 in case the current source code is good and with a
186 -code between 1 and 127 (included) in case the current source code is
187 -bad.
185 +exit with code 0 in case the current source code is good. Exit with a
186 +code between 1 and 127 (inclusive), except 125, if the current
187 +source code is bad.
188
189 Any other exit code will abort the automatic bisect process. (A
190 program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,
191 the value is chopped with "& 0377".)
192
193 +The special exit code 125 should be used when the current source code
194 +cannot be tested. If the "run" script exits with this code, the current
195 +revision will be skipped, see `git bisect skip` above.
196 +
197 You may often find that during bisect you want to have near-constant
198 tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or
199 "revision that does not have this commit needs this patch applied to
git-bisect.sh
+10 -1
@@ -392,7 +392,10 @@ bisect_run () {
392 fi
393
394 # Find current state depending on run success or failure.
395 - if [ $res -gt 0 ]; then
395 + # A special exit code of 125 means cannot test.
396 + if [ $res -eq 125 ]; then
397 + state='skip'
398 + elif [ $res -gt 0 ]; then
399 state='bad'
400 else
401 state='good'
@@ -404,6 +407,12 @@ bisect_run () {
407
408 cat "$GIT_DIR/BISECT_RUN"
409
410 + if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
411 + > /dev/null; then
412 + echo >&2 "bisect run cannot continue any more"
413 + exit $res
414 + fi
415 +
416 if [ $res -ne 0 ]; then
417 echo >&2 "bisect run failed:"
418 echo >&2 "'bisect_state $state' exited with error code $res"
t/t6030-bisect-porcelain.sh
+40
@@ -177,6 +177,46 @@ test_expect_success 'bisect skip and bisect replay' '
177 git bisect reset
178 '
179
180 +HASH6=
181 +test_expect_success 'bisect run & skip: cannot tell between 2' '
182 + add_line_into_file "6: Yet a line." hello &&
183 + HASH6=$(git rev-parse --verify HEAD) &&
184 + echo "#"\!"/bin/sh" > test_script.sh &&
185 + echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
186 + echo "grep line hello > /dev/null" >> test_script.sh &&
187 + echo "test \$? -ne 0" >> test_script.sh &&
188 + chmod +x test_script.sh &&
189 + git bisect start $HASH6 $HASH1 &&
190 + if git bisect run ./test_script.sh > my_bisect_log.txt
191 + then
192 + echo Oops, should have failed.
193 + false
194 + else
195 + test $? -eq 2 &&
196 + grep "first bad commit could be any of" my_bisect_log.txt &&
197 + ! grep $HASH3 my_bisect_log.txt &&
198 + ! grep $HASH6 my_bisect_log.txt &&
199 + grep $HASH4 my_bisect_log.txt &&
200 + grep $HASH5 my_bisect_log.txt
201 + fi
202 +'
203 +
204 +HASH7=
205 +test_expect_success 'bisect run & skip: find first bad' '
206 + git bisect reset &&
207 + add_line_into_file "7: Should be the last line." hello &&
208 + HASH7=$(git rev-parse --verify HEAD) &&
209 + echo "#"\!"/bin/sh" > test_script.sh &&
210 + echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
211 + echo "tail -1 hello | grep day > /dev/null && exit 125" >> test_script.sh &&
212 + echo "grep Yet hello > /dev/null" >> test_script.sh &&
213 + echo "test \$? -ne 0" >> test_script.sh &&
214 + chmod +x test_script.sh &&
215 + git bisect start $HASH7 $HASH1 &&
216 + git bisect run ./test_script.sh > my_bisect_log.txt &&
217 + grep "$HASH6 is first bad commit" my_bisect_log.txt
218 +'
219 +
220 #
221 #
222 test_done