Skip to content

Commit 9eec6a1

Browse files
committed
Merge branch 'jk/end-of-options'
"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 "--"
2 parents 3c8f932 + 9385174 commit 9eec6a1

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

parse-options.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,13 +930,18 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
930930
continue;
931931
}
932932

933-
if (!arg[2] /* "--" */ ||
934-
!strcmp(arg + 2, "end-of-options")) {
933+
if (!arg[2] /* "--" */) {
935934
if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) {
936935
ctx->argc--;
937936
ctx->argv++;
938937
}
939938
break;
939+
} else if (!strcmp(arg + 2, "end-of-options")) {
940+
if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN_OPT)) {
941+
ctx->argc--;
942+
ctx->argv++;
943+
}
944+
break;
940945
}
941946

942947
if (internal_help && !strcmp(arg + 2, "help-all"))

t/t7102-reset.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,12 @@ test_expect_success 'reset --mixed sets up work tree' '
616616
test_must_be_empty actual
617617
'
618618

619+
test_expect_success 'reset handles --end-of-options' '
620+
git update-ref refs/heads/--foo HEAD^ &&
621+
git log -1 --format=%s refs/heads/--foo >expect &&
622+
git reset --hard --end-of-options --foo &&
623+
git log -1 --format=%s HEAD >actual &&
624+
test_cmp expect actual
625+
'
626+
619627
test_done

t/t9350-fast-export.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,14 @@ test_expect_success 'fast-export --first-parent outputs all revisions output by
791791
)
792792
'
793793

794+
test_expect_success 'fast-export handles --end-of-options' '
795+
git update-ref refs/heads/nodash HEAD &&
796+
git update-ref refs/heads/--dashes HEAD &&
797+
git fast-export --end-of-options nodash >expect &&
798+
git fast-export --end-of-options --dashes >actual.raw &&
799+
# fix up lines which mention the ref for comparison
800+
sed s/--dashes/nodash/ <actual.raw >actual &&
801+
test_cmp expect actual
802+
'
803+
794804
test_done

0 commit comments

Comments
 (0)