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>
Christian Couder committed
May 23, 2008 at 00:39 UTC
ba963de859e76a63d447345eeb3e134116d02433
2 files changed
+28
-12
git-bisect.sh
+24
-6
@@ -133,11 +133,29 @@ bisect_start() {
133
esac
134
done
135
136
- sq "$@" >"$GIT_DIR/BISECT_NAMES"
137
- echo "$start_head" >"$GIT_DIR/BISECT_START"
138
- eval "$eval"
139
- echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
136
+ #
137
+ # Change state.
138
+ # In case of mistaken revs or checkout error, or signals received,
139
+ # "bisect_auto_next" below may exit or misbehave.
140
+ # We have to trap this to be able to clean up using
141
+ # "bisect_clean_state".
142
+ #
143
+ trap 'bisect_clean_state' 0
144
+ trap 'exit 255' 1 2 3 15
145
+
146
+ #
147
+ # Write new start state.
148
+ #
149
+ sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
150
+ echo "$start_head" >"$GIT_DIR/BISECT_START" &&
151
+ eval "$eval" &&
152
+ echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
153
+ #
154
+ # Check if we can proceed to the next bisect state.
155
+ #
156
bisect_auto_next
157
+
158
+ trap '-' 0
159
}
160
161
bisect_write() {
@@ -149,9 +167,9 @@ bisect_write() {
167
good|skip) tag="$state"-"$rev" ;;
168
*) die "Bad bisect_write argument: $state" ;;
169
esac
152
- git update-ref "refs/bisect/$tag" "$rev"
170
+ git update-ref "refs/bisect/$tag" "$rev" || exit
171
echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
154
- test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
172
+ test -n "$nolog" || echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
173
}
174
175
bisect_state() {
t/t6030-bisect-porcelain.sh
+4
-6
@@ -147,7 +147,7 @@ test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' '
147
test_must_fail test -e .git/BISECT_START
148
'
149
150
-test_expect_failure 'bisect start: no ".git/BISECT_START" if mistaken rev' '
150
+test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
151
git bisect start $HASH4 $HASH1 -- &&
152
git bisect good &&
153
test_must_fail git bisect start $HASH1 $HASH4 -- &&
@@ -156,19 +156,17 @@ test_expect_failure 'bisect start: no ".git/BISECT_START" if mistaken rev' '
156
test_must_fail test -e .git/BISECT_START
157
'
158
159
-test_expect_failure 'bisect start: no ".git/BISECT_START" if checkout error' '
159
+test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
160
echo "temp stuff" > hello &&
161
test_must_fail git bisect start $HASH4 $HASH1 -- &&
162
git branch &&
163
git branch > branch.output &&
164
grep "* other" branch.output > /dev/null &&
165
test_must_fail test -e .git/BISECT_START &&
166
- test -z "$(git for-each-ref "refs/bisect/*")"
166
+ test -z "$(git for-each-ref "refs/bisect/*")" &&
167
+ git checkout HEAD hello
168
'
169
169
-# This cleanup is needed whatever the result of the above test.
170
-git checkout HEAD hello
171
-
170
# $HASH1 is good, $HASH4 is bad, we skip $HASH3
171
# but $HASH2 is bad,
172
# so we should find $HASH2 as the first bad commit