Skip to content

Commit 1b249ff

Browse files
chriscoolgitster
authored andcommitted
bisect: fix quoting TRIED revs when "bad" commit is also "skip"ped
When the "bad" commit was also "skip"ped and when more than one commit was skipped, the "filter_skipped" function would have printed something like: bisect_rev=<hash1>|<hash2> (where <hash1> and <hash2> are hexadecimal sha1 hashes) and this would have been evaled later as piping "bisect_rev=<hash1>" into "<hash2>", which would have failed. So this patch makes the "filter_skipped" function properly quote what it outputs, so that it will print something like: bisect_rev='<hash1>|<hash2>' which will be properly evaled later. The caller was not stopping properly because the scriptlet this function returned to be evaled was not strung together with && and because of this, an error in an earlier part of the output was simply ignored. A test case is added to the test suite. And while at it, we also initialize the VARS, FOUND and TRIED variables, so that we protect ourselves from environment variables the user may have with these names. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 718258e commit 1b249ff

File tree

2 files changed

+66
-35
lines changed

2 files changed

+66
-35
lines changed

git-bisect.sh

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -269,56 +269,62 @@ filter_skipped() {
269269

270270
# Let's parse the output of:
271271
# "git rev-list --bisect-vars --bisect-all ..."
272-
eval_rev_list "$_eval" | while read hash line
273-
do
274-
case "$VARS,$FOUND,$TRIED,$hash" in
275-
# We display some vars.
276-
1,*,*,*) echo "$hash $line" ;;
277-
278-
# Split line.
279-
,*,*,---*) ;;
280-
281-
# We had nothing to search.
272+
eval_rev_list "$_eval" | {
273+
VARS= FOUND= TRIED=
274+
while read hash line
275+
do
276+
case "$VARS,$FOUND,$TRIED,$hash" in
277+
1,*,*,*)
278+
# "bisect_foo=bar" read from rev-list output.
279+
echo "$hash &&"
280+
;;
281+
,*,*,---*)
282+
# Separator
283+
;;
282284
,,,bisect_rev*)
283-
echo "bisect_rev="
285+
# We had nothing to search.
286+
echo "bisect_rev= &&"
284287
VARS=1
285288
;;
286-
287-
# We did not find a good bisect rev.
288-
# This should happen only if the "bad"
289-
# commit is also a "skip" commit.
290289
,,*,bisect_rev*)
291-
echo "bisect_rev=$TRIED"
290+
# We did not find a good bisect rev.
291+
# This should happen only if the "bad"
292+
# commit is also a "skip" commit.
293+
echo "bisect_rev='$TRIED' &&"
292294
VARS=1
293295
;;
294-
295-
# We are searching.
296296
,,*,*)
297+
# We are searching.
297298
TRIED="${TRIED:+$TRIED|}$hash"
298299
case "$_skip" in
299300
*$hash*) ;;
300301
*)
301-
echo "bisect_rev=$hash"
302-
echo "bisect_tried=\"$TRIED\""
302+
echo "bisect_rev=$hash &&"
303+
echo "bisect_tried='$TRIED' &&"
303304
FOUND=1
304305
;;
305306
esac
306307
;;
307-
308-
# We have already found a rev to be tested.
309-
,1,*,bisect_rev*) VARS=1 ;;
310-
,1,*,*) ;;
311-
312-
# ???
313-
*) die "filter_skipped error " \
314-
"VARS: '$VARS' " \
315-
"FOUND: '$FOUND' " \
316-
"TRIED: '$TRIED' " \
317-
"hash: '$hash' " \
318-
"line: '$line'"
319-
;;
320-
esac
321-
done
308+
,1,*,bisect_rev*)
309+
# We have already found a rev to be tested.
310+
VARS=1
311+
;;
312+
,1,*,*)
313+
;;
314+
*)
315+
# Unexpected input
316+
echo "die 'filter_skipped error'"
317+
die "filter_skipped error " \
318+
"VARS: '$VARS' " \
319+
"FOUND: '$FOUND' " \
320+
"TRIED: '$TRIED' " \
321+
"hash: '$hash' " \
322+
"line: '$line'"
323+
;;
324+
esac
325+
done
326+
echo ':'
327+
}
322328
}
323329

324330
exit_if_skipped_commits () {

t/t6030-bisect-porcelain.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,31 @@ test_expect_success 'bisect skip: cannot tell between 2 commits' '
224224
fi
225225
'
226226

227+
# $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
228+
# and $HASH2 is good,
229+
# so we should not be able to tell the first bad commit
230+
# among $HASH3 and $HASH4
231+
test_expect_success 'bisect skip: with commit both bad and skipped' '
232+
git bisect start &&
233+
git bisect skip &&
234+
git bisect bad &&
235+
git bisect good $HASH1 &&
236+
git bisect skip &&
237+
if git bisect good > my_bisect_log.txt
238+
then
239+
echo Oops, should have failed.
240+
false
241+
else
242+
test $? -eq 2 &&
243+
grep "first bad commit could be any of" my_bisect_log.txt &&
244+
! grep $HASH1 my_bisect_log.txt &&
245+
! grep $HASH2 my_bisect_log.txt &&
246+
grep $HASH3 my_bisect_log.txt &&
247+
grep $HASH4 my_bisect_log.txt &&
248+
git bisect reset
249+
fi
250+
'
251+
227252
# We want to automatically find the commit that
228253
# introduced "Another" into hello.
229254
test_expect_success \

0 commit comments

Comments
 (0)