@matheusbsbs / matheus-bagliano / commits / 634f246444
Fork 0

bisect: use a detached HEAD to bisect

When "git bisect" was first written, it was not possible to checkout a detached HEAD. The detached feature appeared latter. That's why before this patch the "git bisect" process used a "bisect" branch to checkout new revisions to be tested (and also a "new-bisect" one to check if the checkouts could work). This patch makes "git bisect" checkout revisions to be tested on a detached HEAD. This simplifies the code a bit. The tests to check that "git bisect" does not start if a "bisect" or a "new-bisect" branch exists are removed as they are not relevant any more. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 23, 2008 at 01:28 UTC 634f246444e6a1675e351f31362e6a375dc44f70
2 files changed +45 -47
git-bisect.sh
+26 -28
@@ -63,40 +63,40 @@ bisect_autostart() {
63
64 bisect_start() {
65 #
66 - # Verify HEAD. If we were bisecting before this, reset to the
67 - # top-of-line master first!
66 + # Verify HEAD.
67 #
68 head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
69 head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
70 die "Bad HEAD - I need a HEAD"
71 +
72 #
73 - # Check that we either already have BISECT_START, or that the
74 - # branches bisect, new-bisect don't exist, to not override them.
73 + # Check if we are bisecting.
74 #
76 - test -s "$GIT_DIR/BISECT_START" ||
77 - if git show-ref --verify -q refs/heads/bisect ||
78 - git show-ref --verify -q refs/heads/new-bisect; then
79 - die 'The branches "bisect" and "new-bisect" must not exist.'
80 - fi
75 start_head=''
82 - case "$head" in
83 - refs/heads/bisect)
76 + if test -s "$GIT_DIR/BISECT_START"
77 + then
78 + # Reset to the rev from where we started.
79 start_head=$(cat "$GIT_DIR/BISECT_START")
80 git checkout "$start_head" || exit
86 - ;;
87 - refs/heads/*|$_x40)
88 - # This error message should only be triggered by cogito usage,
89 - # and cogito users should understand it relates to cg-seek.
90 - [ -s "$GIT_DIR/head-name" ] && die "won't bisect on seeked tree"
91 - start_head="${head#refs/heads/}"
92 - ;;
93 - *)
94 - die "Bad HEAD - strange symbolic ref"
95 - ;;
96 - esac
81 + else
82 + # Get rev from where we start.
83 + case "$head" in
84 + refs/heads/*|$_x40)
85 + # This error message should only be triggered by
86 + # cogito usage, and cogito users should understand
87 + # it relates to cg-seek.
88 + [ -s "$GIT_DIR/head-name" ] &&
89 + die "won't bisect on seeked tree"
90 + start_head="${head#refs/heads/}"
91 + ;;
92 + *)
93 + die "Bad HEAD - strange symbolic ref"
94 + ;;
95 + esac
96 + fi
97
98 #
99 - # Get rid of any old bisect state
99 + # Get rid of any old bisect state.
100 #
101 bisect_clean_state
102
@@ -118,7 +118,7 @@ bisect_start() {
118 break
119 ;;
120 *)
121 - rev=$(git rev-parse --verify "$arg^{commit}" 2>/dev/null) || {
121 + rev=$(git rev-parse -q --verify "$arg^{commit}") || {
122 test $has_double_dash -eq 1 &&
123 die "'$arg' does not appear to be a valid revision"
124 break
@@ -366,9 +366,7 @@ bisect_next() {
366 exit_if_skipped_commits "$bisect_rev"
367
368 echo "Bisecting: $bisect_nr revisions left to test after this"
369 - git branch -D new-bisect 2> /dev/null
370 - git checkout -q -b new-bisect "$bisect_rev" || exit
371 - git branch -M new-bisect bisect
369 + git checkout -q "$bisect_rev" || exit
370 git show-branch "$bisect_rev"
371 }
372
@@ -415,7 +413,7 @@ bisect_reset() {
413
414 bisect_clean_state() {
415 # There may be some refs packed during bisection.
418 - git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* refs/heads/bisect |
416 + git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
417 while read ref hash
418 do
419 git update-ref -d $ref $hash
t/t6030-bisect-porcelain.sh
+19 -19
@@ -322,25 +322,6 @@ test_expect_success 'bisect starting with a detached HEAD' '
322 test $HEAD = $(cat .git/BISECT_START) &&
323 git bisect reset &&
324 test $HEAD = $(git rev-parse --verify HEAD)
325 -
326 -'
327 -
328 -test_expect_success 'bisect refuses to start if branch bisect exists' '
329 - git bisect reset &&
330 - git branch bisect &&
331 - test_must_fail git bisect start &&
332 - git branch -d bisect &&
333 - git checkout -b bisect &&
334 - test_must_fail git bisect start &&
335 - git checkout master &&
336 - git branch -d bisect
337 -'
338 -
339 -test_expect_success 'bisect refuses to start if branch new-bisect exists' '
340 - git bisect reset &&
341 - git branch new-bisect &&
342 - test_must_fail git bisect start &&
343 - git branch -d new-bisect
325 '
326
327 test_expect_success 'bisect errors out if bad and good are mistaken' '
@@ -350,6 +331,25 @@ test_expect_success 'bisect errors out if bad and good are mistaken' '
331 git bisect reset
332 '
333
334 +test_expect_success 'bisect does not create a "bisect" branch' '
335 + git bisect reset &&
336 + git bisect start $HASH7 $HASH1 &&
337 + git branch bisect &&
338 + rev_hash4=$(git rev-parse --verify HEAD) &&
339 + test "$rev_hash4" = "$HASH4" &&
340 + git branch -D bisect &&
341 + git bisect good &&
342 + git branch bisect &&
343 + rev_hash6=$(git rev-parse --verify HEAD) &&
344 + test "$rev_hash6" = "$HASH6" &&
345 + git bisect good > my_bisect_log.txt &&
346 + grep "$HASH7 is first bad commit" my_bisect_log.txt &&
347 + git bisect reset &&
348 + rev_hash6=$(git rev-parse --verify bisect) &&
349 + test "$rev_hash6" = "$HASH6" &&
350 + git branch -D bisect
351 +'
352 +
353 #
354 #
355 test_done