Skip to content

Commit 73c6de0

Browse files
chriscoolgitster
authored andcommitted
bisect: don't use invalid oid as rev when starting
In 06f5608 (bisect--helper: `bisect_start` shell function partially in C, 2019-01-02), we changed the following shell code: - rev=$(git rev-parse -q --verify "$arg^{commit}") || { - test $has_double_dash -eq 1 && - die "$(eval_gettext "'\$arg' does not appear to be a valid revision")" - break - } - revs="$revs $rev" into: + char *commit_id = xstrfmt("%s^{commit}", arg); + if (get_oid(commit_id, &oid) && has_double_dash) + die(_("'%s' does not appear to be a valid " + "revision"), arg); + + string_list_append(&revs, oid_to_hex(&oid)); + free(commit_id); In case of an invalid "arg" when "has_double_dash" is false, the old code would "break" out of the argument loop. In the new C code though, `oid_to_hex(&oid)` is unconditonally appended to "revs". This is wrong first because "oid" is junk as `get_oid(commit_id, &oid)` failed and second because it doesn't break out of the argument loop. Not breaking out of the argument loop means that "arg" is then not treated as a path restriction (which is wrong). Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7397ca3 commit 73c6de0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

builtin/bisect--helper.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,13 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
474474
} else if (starts_with(arg, "--") &&
475475
!one_of(arg, "--term-good", "--term-bad", NULL)) {
476476
return error(_("unrecognized option: '%s'"), arg);
477-
} else {
478-
char *commit_id = xstrfmt("%s^{commit}", arg);
479-
if (get_oid(commit_id, &oid) && has_double_dash)
480-
die(_("'%s' does not appear to be a valid "
481-
"revision"), arg);
482-
477+
} else if (!get_oidf(&oid, "%s^{commit}", arg)) {
483478
string_list_append(&revs, oid_to_hex(&oid));
484-
free(commit_id);
479+
} else if (has_double_dash) {
480+
die(_("'%s' does not appear to be a valid "
481+
"revision"), arg);
482+
} else {
483+
break;
485484
}
486485
}
487486
pathspec_pos = i;

t/t6030-bisect-porcelain.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ test_expect_success 'bisect fails if given any junk instead of revs' '
8282
git bisect bad $HASH4
8383
'
8484

85+
test_expect_success 'bisect start without -- takes unknown arg as pathspec' '
86+
git bisect reset &&
87+
git bisect start foo bar &&
88+
grep foo ".git/BISECT_NAMES" &&
89+
grep bar ".git/BISECT_NAMES"
90+
'
91+
8592
test_expect_success 'bisect reset: back in the master branch' '
8693
git bisect reset &&
8794
echo "* master" > branch.expect &&

0 commit comments

Comments
 (0)