Skip to content

Commit 51b4594

Browse files
peffgitster
authored andcommitted
parse-options: allow --end-of-options as a synonym for "--"
The revision option parser recently learned about --end-of-options, but that's not quite enough for all callers. Some of them, like git-log, pick out some options using parse_options(), and then feed the remainder to setup_revisions(). For those cases we need to stop parse_options() from finding more options when it sees --end-of-options, and to retain that option in argv so that setup_revisions() can see it as well. Let's handle this the same as we do "--". We can even piggy-back on the handling of PARSE_OPT_KEEP_DASHDASH, because any caller that wants to retain one will want to retain the other. I've included two tests here. The "log" test covers "--source", which is one of the options it handles with parse_options(), and would fail before this patch. There's also a test that uses the parse-options helper directly. That confirms that the option is handled correctly even in cases without KEEP_DASHDASH or setup_revisions(). I.e., it is safe to use --end-of-options in place of "--" in other programs. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19e8789 commit 51b4594

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

parse-options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
780780
continue;
781781
}
782782

783-
if (!arg[2]) { /* "--" */
783+
if (!arg[2] /* "--" */ ||
784+
!strcmp(arg + 2, "end-of-options")) {
784785
if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) {
785786
ctx->argc--;
786787
ctx->argv++;

t/t0040-parse-options.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,11 @@ test_expect_success 'GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS works' '
399399
test-tool parse-options --ye
400400
'
401401

402+
test_expect_success '--end-of-options treats remainder as args' '
403+
test-tool parse-options \
404+
--expect="verbose: -1" \
405+
--expect="arg 00: --verbose" \
406+
--end-of-options --verbose
407+
'
408+
402409
test_done

t/t4202-log.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,4 +1707,11 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' '
17071707
test_must_fail git log --exclude-promisor-objects source-a
17081708
'
17091709

1710+
test_expect_success 'log --end-of-options' '
1711+
git update-ref refs/heads/--source HEAD &&
1712+
git log --end-of-options --source >actual &&
1713+
git log >expect &&
1714+
test_cmp expect actual
1715+
'
1716+
17101717
test_done

0 commit comments

Comments
 (0)