Skip to content

Commit 4764f46

Browse files
jonseymourgitster
authored andcommitted
bisect: move argument parsing before state modification.
Currently 'git bisect start' modifies some state prior to checking that its arguments are valid. This change moves argument validation before state modification with the effect that state modification does not occur unless argument validations succeeds. An existing test is changed to check that new bisect state is not created if arguments are invalid. A new test is added to check that existing bisect state is not modified if arguments are invalid. Signed-off-by: Jon Seymour <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b35acb5 commit 4764f46

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

git-bisect.sh

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ bisect_autostart() {
5959
}
6060

6161
bisect_start() {
62+
#
63+
# Check for one bad and then some good revisions.
64+
#
65+
has_double_dash=0
66+
for arg; do
67+
case "$arg" in --) has_double_dash=1; break ;; esac
68+
done
69+
orig_args=$(git rev-parse --sq-quote "$@")
70+
bad_seen=0
71+
eval=''
72+
while [ $# -gt 0 ]; do
73+
arg="$1"
74+
case "$arg" in
75+
--)
76+
shift
77+
break
78+
;;
79+
*)
80+
rev=$(git rev-parse -q --verify "$arg^{commit}") || {
81+
test $has_double_dash -eq 1 &&
82+
die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
83+
break
84+
}
85+
case $bad_seen in
86+
0) state='bad' ; bad_seen=1 ;;
87+
*) state='good' ;;
88+
esac
89+
eval="$eval bisect_write '$state' '$rev' 'nolog'; "
90+
shift
91+
;;
92+
esac
93+
done
94+
6295
#
6396
# Verify HEAD.
6497
#
@@ -97,39 +130,6 @@ bisect_start() {
97130
#
98131
bisect_clean_state || exit
99132

100-
#
101-
# Check for one bad and then some good revisions.
102-
#
103-
has_double_dash=0
104-
for arg; do
105-
case "$arg" in --) has_double_dash=1; break ;; esac
106-
done
107-
orig_args=$(git rev-parse --sq-quote "$@")
108-
bad_seen=0
109-
eval=''
110-
while [ $# -gt 0 ]; do
111-
arg="$1"
112-
case "$arg" in
113-
--)
114-
shift
115-
break
116-
;;
117-
*)
118-
rev=$(git rev-parse -q --verify "$arg^{commit}") || {
119-
test $has_double_dash -eq 1 &&
120-
die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
121-
break
122-
}
123-
case $bad_seen in
124-
0) state='bad' ; bad_seen=1 ;;
125-
*) state='good' ;;
126-
esac
127-
eval="$eval bisect_write '$state' '$rev' 'nolog'; "
128-
shift
129-
;;
130-
esac
131-
done
132-
133133
#
134134
# Change state.
135135
# In case of mistaken revs or checkout error, or signals received,

t/t6030-bisect-porcelain.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,23 @@ test_expect_success 'bisect start: back in good branch' '
138138
grep "* other" branch.output > /dev/null
139139
'
140140

141-
test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' '
142-
git bisect start $HASH4 $HASH1 -- &&
143-
git bisect good &&
141+
test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' '
142+
git bisect reset &&
144143
test_must_fail git bisect start $HASH4 foo -- &&
145144
git branch > branch.output &&
146145
grep "* other" branch.output > /dev/null &&
147146
test_must_fail test -e .git/BISECT_START
148147
'
149148

149+
test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
150+
git bisect start $HASH4 $HASH1 -- &&
151+
git bisect good &&
152+
cp .git/BISECT_START saved &&
153+
test_must_fail git bisect start $HASH4 foo -- &&
154+
git branch > branch.output &&
155+
grep "* (no branch)" branch.output > /dev/null &&
156+
test_cmp saved .git/BISECT_START
157+
'
150158
test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
151159
git bisect start $HASH4 $HASH1 -- &&
152160
git bisect good &&

0 commit comments

Comments
 (0)