bisect: trap critical errors in "bisect_start"

Before this patch, when using "git bisect start" with mistaken revs
or when the checkout of the branch we want to test failed, we exited
after having written files like ".git/BISECT_START",
".git/BISECT_NAMES" and after having written "refs/bisect/bad" and
"refs/bisect/good-*" refs.

With this patch we trap all errors that can happen when writing the
new state and when we are in "bisect_next". So that we can try to
clean up everything in case of problems, using "bisect_clean_state".

This patch also contains a "bisect_write" cleanup to make it exit
on error and return 0 otherwise.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder
2008-05-23 00:39:22 +02:00
committed by Junio C Hamano
parent 9d0cd91c4e
commit ba963de859
2 changed files with 28 additions and 12 deletions

View File

@ -133,11 +133,29 @@ bisect_start() {
esac esac
done done
sq "$@" >"$GIT_DIR/BISECT_NAMES" #
echo "$start_head" >"$GIT_DIR/BISECT_START" # Change state.
eval "$eval" # In case of mistaken revs or checkout error, or signals received,
echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" # "bisect_auto_next" below may exit or misbehave.
# We have to trap this to be able to clean up using
# "bisect_clean_state".
#
trap 'bisect_clean_state' 0
trap 'exit 255' 1 2 3 15
#
# Write new start state.
#
sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
echo "$start_head" >"$GIT_DIR/BISECT_START" &&
eval "$eval" &&
echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
#
# Check if we can proceed to the next bisect state.
#
bisect_auto_next bisect_auto_next
trap '-' 0
} }
bisect_write() { bisect_write() {
@ -149,9 +167,9 @@ bisect_write() {
good|skip) tag="$state"-"$rev" ;; good|skip) tag="$state"-"$rev" ;;
*) die "Bad bisect_write argument: $state" ;; *) die "Bad bisect_write argument: $state" ;;
esac esac
git update-ref "refs/bisect/$tag" "$rev" git update-ref "refs/bisect/$tag" "$rev" || exit
echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG" echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG" test -n "$nolog" || echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
} }
bisect_state() { bisect_state() {

View File

@ -147,7 +147,7 @@ test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' '
test_must_fail test -e .git/BISECT_START test_must_fail test -e .git/BISECT_START
' '
test_expect_failure 'bisect start: no ".git/BISECT_START" if mistaken rev' ' test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
git bisect start $HASH4 $HASH1 -- && git bisect start $HASH4 $HASH1 -- &&
git bisect good && git bisect good &&
test_must_fail git bisect start $HASH1 $HASH4 -- && test_must_fail git bisect start $HASH1 $HASH4 -- &&
@ -156,19 +156,17 @@ test_expect_failure 'bisect start: no ".git/BISECT_START" if mistaken rev' '
test_must_fail test -e .git/BISECT_START test_must_fail test -e .git/BISECT_START
' '
test_expect_failure 'bisect start: no ".git/BISECT_START" if checkout error' ' test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
echo "temp stuff" > hello && echo "temp stuff" > hello &&
test_must_fail git bisect start $HASH4 $HASH1 -- && test_must_fail git bisect start $HASH4 $HASH1 -- &&
git branch && git branch &&
git branch > branch.output && git branch > branch.output &&
grep "* other" branch.output > /dev/null && grep "* other" branch.output > /dev/null &&
test_must_fail test -e .git/BISECT_START && test_must_fail test -e .git/BISECT_START &&
test -z "$(git for-each-ref "refs/bisect/*")" test -z "$(git for-each-ref "refs/bisect/*")" &&
git checkout HEAD hello
' '
# This cleanup is needed whatever the result of the above test.
git checkout HEAD hello
# $HASH1 is good, $HASH4 is bad, we skip $HASH3 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
# but $HASH2 is bad, # but $HASH2 is bad,
# so we should find $HASH2 as the first bad commit # so we should find $HASH2 as the first bad commit