Merge branch 'jk/end-of-options' into maint-2.43

"git $cmd --end-of-options --rev -- --path" for some $cmd failed
to interpret "--rev" as a rev, and "--path" as a path.  This was
fixed for many programs like "reset" and "checkout".

* jk/end-of-options:
  parse-options: decouple "--end-of-options" and "--"
This commit is contained in:
Junio C Hamano 2024-02-08 16:22:02 -08:00
commit 19fa15fb2d
3 changed files with 25 additions and 2 deletions

View file

@ -929,13 +929,18 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
continue;
}
if (!arg[2] /* "--" */ ||
!strcmp(arg + 2, "end-of-options")) {
if (!arg[2] /* "--" */) {
if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) {
ctx->argc--;
ctx->argv++;
}
break;
} else if (!strcmp(arg + 2, "end-of-options")) {
if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN_OPT)) {
ctx->argc--;
ctx->argv++;
}
break;
}
if (internal_help && !strcmp(arg + 2, "help-all"))

View file

@ -616,4 +616,12 @@ test_expect_success 'reset --mixed sets up work tree' '
test_must_be_empty actual
'
test_expect_success 'reset handles --end-of-options' '
git update-ref refs/heads/--foo HEAD^ &&
git log -1 --format=%s refs/heads/--foo >expect &&
git reset --hard --end-of-options --foo &&
git log -1 --format=%s HEAD >actual &&
test_cmp expect actual
'
test_done

View file

@ -791,4 +791,14 @@ test_expect_success 'fast-export --first-parent outputs all revisions output by
)
'
test_expect_success 'fast-export handles --end-of-options' '
git update-ref refs/heads/nodash HEAD &&
git update-ref refs/heads/--dashes HEAD &&
git fast-export --end-of-options nodash >expect &&
git fast-export --end-of-options --dashes >actual.raw &&
# fix up lines which mention the ref for comparison
sed s/--dashes/nodash/ <actual.raw >actual &&
test_cmp expect actual
'
test_done