Skip to content

Commit 109440c

Browse files
committed
Merge branch 'gp/bisect-fix' into maint
* 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 df2740b + 42ba5ee commit 109440c

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
@@ -78,7 +78,7 @@ Oh, and then after you want to reset to the original head, do a
7878
$ git bisect reset
7979
------------------------------------------------
8080

81-
to get back to the master branch, instead of being in one of the
81+
to get back to the original branch, instead of being in one of the
8282
bisection branches ("git bisect start" will do that for you too,
8383
actually: it will reset the bisection state, and before it does that
8484
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
@@ -65,14 +65,19 @@ bisect_start() {
6565
head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
6666
head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
6767
die "Bad HEAD - I need a HEAD"
68+
#
69+
# Check that we either already have BISECT_START, or that the
70+
# branches bisect, new-bisect don't exist, to not override them.
71+
#
72+
test -s "$GIT_DIR/BISECT_START" ||
73+
if git show-ref --verify -q refs/heads/bisect ||
74+
git show-ref --verify -q refs/heads/new-bisect; then
75+
die 'The branches "bisect" and "new-bisect" must not exist.'
76+
fi
6877
start_head=''
6978
case "$head" in
7079
refs/heads/bisect)
71-
if [ -s "$GIT_DIR/BISECT_START" ]; then
72-
branch=`cat "$GIT_DIR/BISECT_START"`
73-
else
74-
branch=master
75-
fi
80+
branch=`cat "$GIT_DIR/BISECT_START"`
7681
git checkout $branch || exit
7782
;;
7883
refs/heads/*|$_x40)
@@ -215,18 +220,33 @@ bisect_auto_next() {
215220
bisect_next_check && bisect_next || :
216221
}
217222

223+
eval_rev_list() {
224+
_eval="$1"
225+
226+
eval $_eval
227+
res=$?
228+
229+
if [ $res -ne 0 ]; then
230+
echo >&2 "'git rev-list --bisect-vars' failed:"
231+
echo >&2 "maybe you mistake good and bad revs?"
232+
exit $res
233+
fi
234+
235+
return $res
236+
}
237+
218238
filter_skipped() {
219239
_eval="$1"
220240
_skip="$2"
221241

222242
if [ -z "$_skip" ]; then
223-
eval $_eval
243+
eval_rev_list "$_eval"
224244
return
225245
fi
226246

227247
# Let's parse the output of:
228248
# "git rev-list --bisect-vars --bisect-all ..."
229-
eval $_eval | while read hash line
249+
eval_rev_list "$_eval" | while read hash line
230250
do
231251
case "$VARS,$FOUND,$TRIED,$hash" in
232252
# We display some vars.
@@ -324,8 +344,8 @@ bisect_next() {
324344
exit_if_skipped_commits "$bisect_rev"
325345

326346
echo "Bisecting: $bisect_nr revisions left to test after this"
327-
git branch -f new-bisect "$bisect_rev"
328-
git checkout -q new-bisect || exit
347+
git branch -D new-bisect 2> /dev/null
348+
git checkout -q -b new-bisect "$bisect_rev" || exit
329349
git branch -M new-bisect bisect
330350
git show-branch "$bisect_rev"
331351
}

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)