]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/end-of-options' into jc/sparse-checkout-set-add-end-of-options
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Dec 2023 05:49:33 +0000 (21:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Dec 2023 05:49:33 +0000 (21:49 -0800)
* jk/end-of-options:
  parse-options: decouple "--end-of-options" and "--"

parse-options.c
t/t7102-reset.sh
t/t9350-fast-export.sh

index e0c94b0546b5487c5b324c4c2b76d668289e8b10..d50962062ead7dfb4d831199a5dca2e0b4316227 100644 (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"))
index 4287863ae6cab9a67564c9328effd68d2c186ab6..62d9f846ce86c54745eb87619d14fefc005d6fe3 100755 (executable)
@@ -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
index 26c25c0eb2ba57fa90c682950fda4899329474f8..e9a12c18bbd3f8bd43659d0b4eee0e4dfbad30ab 100755 (executable)
@@ -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