Skip to content

Commit 823ea12

Browse files
chriscoolgitster
authored andcommitted
bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting
It seems simpler and safer to use the BISECT_START file everywhere to decide if we are bisecting or not, instead of using it in some places and BISECT_NAMES in other places. In commit 6459c7c (Nov 18 2007, Bisect: use "$GIT_DIR/BISECT_NAMES" to check if we are bisecting.), we decided to use BISECT_NAMES but code changed a lot and we now have to check BISECT_START first in the "bisect_start" function anyway. This patch also makes things a little bit safer by creating the BISECT_START file first and deleting it last, and also by adding checks in "bisect_clean_state". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent efb98b4 commit 823ea12

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

git-bisect.sh

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sq() {
4444
}
4545

4646
bisect_autostart() {
47-
test -f "$GIT_DIR/BISECT_NAMES" || {
47+
test -s "$GIT_DIR/BISECT_START" || {
4848
echo >&2 'You need to start by "git bisect start"'
4949
if test -t 0
5050
then
@@ -98,7 +98,7 @@ bisect_start() {
9898
#
9999
# Get rid of any old bisect state.
100100
#
101-
bisect_clean_state
101+
bisect_clean_state || exit
102102

103103
#
104104
# Check for one bad and then some good revisions.
@@ -146,8 +146,8 @@ bisect_start() {
146146
#
147147
# Write new start state.
148148
#
149-
sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
150149
echo "$start_head" >"$GIT_DIR/BISECT_START" &&
150+
sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
151151
eval "$eval" &&
152152
echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
153153
#
@@ -226,7 +226,7 @@ bisect_next_check() {
226226
;;
227227
*)
228228
THEN=''
229-
test -f "$GIT_DIR/BISECT_NAMES" || {
229+
test -s "$GIT_DIR/BISECT_START" || {
230230
echo >&2 'You need to start by "git bisect start".'
231231
THEN='then '
232232
}
@@ -392,16 +392,12 @@ bisect_visualize() {
392392
}
393393

394394
bisect_reset() {
395-
test -f "$GIT_DIR/BISECT_NAMES" || {
395+
test -s "$GIT_DIR/BISECT_START" || {
396396
echo "We are not bisecting."
397397
return
398398
}
399399
case "$#" in
400-
0) if [ -s "$GIT_DIR/BISECT_START" ]; then
401-
branch=`cat "$GIT_DIR/BISECT_START"`
402-
else
403-
branch=master
404-
fi ;;
400+
0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
405401
1) git show-ref --verify --quiet -- "refs/heads/$1" ||
406402
die "$1 does not seem to be a valid branch"
407403
branch="$1" ;;
@@ -416,14 +412,15 @@ bisect_clean_state() {
416412
git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
417413
while read ref hash
418414
do
419-
git update-ref -d $ref $hash
415+
git update-ref -d $ref $hash || exit
420416
done
421-
rm -f "$GIT_DIR/BISECT_START"
422-
rm -f "$GIT_DIR/BISECT_LOG"
423-
rm -f "$GIT_DIR/BISECT_NAMES"
424-
rm -f "$GIT_DIR/BISECT_RUN"
417+
rm -f "$GIT_DIR/BISECT_LOG" &&
418+
rm -f "$GIT_DIR/BISECT_NAMES" &&
419+
rm -f "$GIT_DIR/BISECT_RUN" &&
425420
# Cleanup head-name if it got left by an old version of git-bisect
426-
rm -f "$GIT_DIR/head-name"
421+
rm -f "$GIT_DIR/head-name" &&
422+
423+
rm -f "$GIT_DIR/BISECT_START"
427424
}
428425

429426
bisect_replay () {

0 commit comments

Comments
 (0)