Skip to content

Commit de1fee2

Browse files
committed
Merge branch 'ow/rev-parse-parseopt-fix'
The parser in the script interface to parse-options in "git rev-parse" has been updated to diagnose a bogus input correctly. * ow/rev-parse-parseopt-fix: rev-parse --parseopt: detect missing opt-spec
2 parents e4ffba4 + f20b9c3 commit de1fee2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

builtin/rev-parse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
479479
if (!s)
480480
s = help;
481481

482+
if (s == sb.buf)
483+
die(_("missing opt-spec before option flags"));
484+
482485
if (s - sb.buf == 1) /* short option only */
483486
o->short_name = *sb.buf;
484487
else if (sb.buf[1] != ',') /* long option only */

t/t1502-rev-parse-parseopt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ test_expect_success 'test --parseopt help output: "wrapped" options normal "or:"
306306
test_cmp expect actual
307307
'
308308

309+
test_expect_success 'test --parseopt invalid opt-spec' '
310+
test_write_lines x -- "=, x" >spec &&
311+
echo "fatal: missing opt-spec before option flags" >expect &&
312+
test_must_fail git rev-parse --parseopt -- >out <spec 2>err &&
313+
test_cmp expect err
314+
'
315+
309316
test_expect_success 'test --parseopt help output: multi-line blurb after empty line' '
310317
sed -e "s/^|//" >spec <<-\EOF &&
311318
|cmd [--some-option]

0 commit comments

Comments
 (0)