Skip to content

Commit e338907

Browse files
chriscoolgitster
authored andcommitted
bisect: fix bad rev checking in "git bisect good"
It seems that "git bisect good" and "git bisect skip" have never properly checked arguments that have been passed to them. As soon as one of them can be parsed as a SHA1, no error or warning would be given. This is because 'git rev-parse --revs-only --no-flags "$@"' always "exit 0" and outputs all the SHA1 it can found from parsing "$@". This patch fix this by using, for each "bisect good" argument, the same logic as for the "bisect bad" argument. While at it, this patch teaches "bisect bad" to give a meaningfull error message when it is passed more than one argument. Note that if "git bisect good" or "git bisect skip" is given some proper revs and then something that is not a proper rev, then the first proper revs will still have been marked as "good" or "skip". Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a710522 commit e338907

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

git-bisect.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,16 @@ bisect_state() {
151151
rev=$(git rev-parse --verify HEAD) ||
152152
die "Bad rev input: HEAD"
153153
bisect_write "$state" "$rev" ;;
154-
2,bad)
155-
rev=$(git rev-parse --verify "$2^{commit}") ||
156-
die "Bad rev input: $2"
157-
bisect_write "$state" "$rev" ;;
158-
*,good|*,skip)
154+
2,bad|*,good|*,skip)
159155
shift
160-
revs=$(git rev-parse --revs-only --no-flags "$@") &&
161-
test '' != "$revs" || die "Bad rev input: $@"
162-
for rev in $revs
156+
for rev in "$@"
163157
do
164158
rev=$(git rev-parse --verify "$rev^{commit}") ||
165-
die "Bad rev commit: $rev^{commit}"
159+
die "Bad rev input: $rev"
166160
bisect_write "$state" "$rev"
167161
done ;;
162+
*,bad)
163+
die "'git bisect bad' can take only one argument." ;;
168164
*)
169165
usage ;;
170166
esac

t/t6030-bisect-porcelain.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ test_expect_success 'bisect start with one bad and good' '
7171
git bisect next
7272
'
7373

74+
test_expect_success 'bisect good and bad fails if not given only revs' '
75+
git bisect reset &&
76+
git bisect start &&
77+
test_must_fail git bisect good foo $HASH1 &&
78+
test_must_fail git bisect good $HASH1 bar &&
79+
test_must_fail git bisect bad frotz &&
80+
test_must_fail git bisect bad $HASH3 $HASH4 &&
81+
test_must_fail git bisect skip bar $HASH3 &&
82+
test_must_fail git bisect skip $HASH1 foo &&
83+
git bisect good $HASH1 &&
84+
git bisect bad $HASH4
85+
'
86+
7487
test_expect_success 'bisect reset: back in the master branch' '
7588
git bisect reset &&
7689
echo "* master" > branch.expect &&

0 commit comments

Comments
 (0)