aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-02-08 16:22:02 -0800
committerJunio C Hamano <gitster@pobox.com>2024-02-08 16:22:02 -0800
commit19fa15fb2d8d002ce382901fa7b31de2853627bd (patch)
treefd1bb65fbc95e93a92cb3ad636aafc45a307fc97
parent4b50f8614100a41c963a6a2d5e7424e0ff4e0863 (diff)
parent9385174627cbb7301b1007912514a66b75d78f31 (diff)
downloadgit-19fa15fb2d8d002ce382901fa7b31de2853627bd.tar.gz
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 "--"
-rw-r--r--parse-options.c9
-rwxr-xr-xt/t7102-reset.sh8
-rwxr-xr-xt/t9350-fast-export.sh10
3 files changed, 25 insertions, 2 deletions
diff --git a/parse-options.c b/parse-options.c
index e0c94b0546..d50962062e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -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"))
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 4287863ae6..62d9f846ce 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -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
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index 26c25c0eb2..e9a12c18bb 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -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