Skip to content

Commit eafa29b

Browse files
committed
Merge branch 'gp/bisect-fix'
* gp/bisect-fix: bisect: print an error message when "git rev-list --bisect-vars" fails git-bisect.sh: don't accidentally override existing branch "bisect"
2 parents 65ea3b8 + 42ba5ee commit eafa29b

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

Documentation/git-bisect.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Oh, and then after you want to reset to the original head, do a
8585
$ git bisect reset
8686
------------------------------------------------
8787

88-
to get back to the master branch, instead of being in one of the
88+
to get back to the original branch, instead of being in one of the
8989
bisection branches ("git bisect start" will do that for you too,
9090
actually: it will reset the bisection state, and before it does that
9191
it checks that you're not using some old bisection branch).

git-bisect.sh

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ bisect_start() {
6969
head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
7070
head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
7171
die "Bad HEAD - I need a HEAD"
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.
75+
#
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
7281
start_head=''
7382
case "$head" in
7483
refs/heads/bisect)
75-
if [ -s "$GIT_DIR/BISECT_START" ]; then
76-
branch=`cat "$GIT_DIR/BISECT_START"`
77-
else
78-
branch=master
79-
fi
84+
branch=`cat "$GIT_DIR/BISECT_START"`
8085
git checkout $branch || exit
8186
;;
8287
refs/heads/*|$_x40)
@@ -219,18 +224,33 @@ bisect_auto_next() {
219224
bisect_next_check && bisect_next || :
220225
}
221226

227+
eval_rev_list() {
228+
_eval="$1"
229+
230+
eval $_eval
231+
res=$?
232+
233+
if [ $res -ne 0 ]; then
234+
echo >&2 "'git rev-list --bisect-vars' failed:"
235+
echo >&2 "maybe you mistake good and bad revs?"
236+
exit $res
237+
fi
238+
239+
return $res
240+
}
241+
222242
filter_skipped() {
223243
_eval="$1"
224244
_skip="$2"
225245

226246
if [ -z "$_skip" ]; then
227-
eval $_eval
247+
eval_rev_list "$_eval"
228248
return
229249
fi
230250

231251
# Let's parse the output of:
232252
# "git rev-list --bisect-vars --bisect-all ..."
233-
eval $_eval | while read hash line
253+
eval_rev_list "$_eval" | while read hash line
234254
do
235255
case "$VARS,$FOUND,$TRIED,$hash" in
236256
# We display some vars.
@@ -328,8 +348,8 @@ bisect_next() {
328348
exit_if_skipped_commits "$bisect_rev"
329349

330350
echo "Bisecting: $bisect_nr revisions left to test after this"
331-
git branch -f new-bisect "$bisect_rev"
332-
git checkout -q new-bisect || exit
351+
git branch -D new-bisect 2> /dev/null
352+
git checkout -q -b new-bisect "$bisect_rev" || exit
333353
git branch -M new-bisect bisect
334354
git show-branch "$bisect_rev"
335355
}

t/t6030-bisect-porcelain.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,31 @@ test_expect_success 'bisect starting with a detached HEAD' '
284284
285285
'
286286

287+
test_expect_success 'bisect refuses to start if branch bisect exists' '
288+
git bisect reset &&
289+
git branch bisect &&
290+
test_must_fail git bisect start &&
291+
git branch -d bisect &&
292+
git checkout -b bisect &&
293+
test_must_fail git bisect start &&
294+
git checkout master &&
295+
git branch -d bisect
296+
'
297+
298+
test_expect_success 'bisect refuses to start if branch new-bisect exists' '
299+
git bisect reset &&
300+
git branch new-bisect &&
301+
test_must_fail git bisect start &&
302+
git branch -d new-bisect
303+
'
304+
305+
test_expect_success 'bisect errors out if bad and good are mistaken' '
306+
git bisect reset &&
307+
test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
308+
grep "mistake good and bad" rev_list_error &&
309+
git bisect reset
310+
'
311+
287312
#
288313
#
289314
test_done

0 commit comments

Comments
 (0)