@matheusbsbs / matheus-bagliano / commits / 823ea1211c
Fork 0

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 6459c7c6786aa9bda0c7a095c9db66c36da0e5f0 (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>

Christian Couder committed May 28, 2008 at 18:57 UTC 823ea1211ca48afc229c84fcc06f66a87fa78303
1 file changed +13 -16
git-bisect.sh
+13 -16
@@ -44,7 +44,7 @@ sq() {
44 }
45
46 bisect_autostart() {
47 - test -f "$GIT_DIR/BISECT_NAMES" || {
47 + test -s "$GIT_DIR/BISECT_START" || {
48 echo >&2 'You need to start by "git bisect start"'
49 if test -t 0
50 then
@@ -98,7 +98,7 @@ bisect_start() {
98 #
99 # Get rid of any old bisect state.
100 #
101 - bisect_clean_state
101 + bisect_clean_state || exit
102
103 #
104 # Check for one bad and then some good revisions.
@@ -146,8 +146,8 @@ bisect_start() {
146 #
147 # Write new start state.
148 #
149 - sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
149 echo "$start_head" >"$GIT_DIR/BISECT_START" &&
150 + sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
151 eval "$eval" &&
152 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
153 #
@@ -226,7 +226,7 @@ bisect_next_check() {
226 ;;
227 *)
228 THEN=''
229 - test -f "$GIT_DIR/BISECT_NAMES" || {
229 + test -s "$GIT_DIR/BISECT_START" || {
230 echo >&2 'You need to start by "git bisect start".'
231 THEN='then '
232 }
@@ -392,16 +392,12 @@ bisect_visualize() {
392 }
393
394 bisect_reset() {
395 - test -f "$GIT_DIR/BISECT_NAMES" || {
395 + test -s "$GIT_DIR/BISECT_START" || {
396 echo "We are not bisecting."
397 return
398 }
399 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") ;;
401 1) git show-ref --verify --quiet -- "refs/heads/$1" ||
402 die "$1 does not seem to be a valid branch"
403 branch="$1" ;;
@@ -416,14 +412,15 @@ bisect_clean_state() {
412 git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
413 while read ref hash
414 do
419 - git update-ref -d $ref $hash
415 + git update-ref -d $ref $hash || exit
416 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" &&
420 # 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"
424 }
425
426 bisect_replay () {