On Wed, Dec 20, 2023 at 11:00 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: > > 93851746 (parse-options: decouple "--end-of-options" and "--", > 2023-12-06) updated the world order to make callers of parse-options > that set PARSE_OPT_KEEP_UNKNOWN_OPT responsible for deciding what to > do with "--end-of-options" they may see after parse_options() returns. > > This unfortunately broke "sparse-checkout set/add", and from this > invocation, > > "git sparse-checkout [add|set] --[no-]cone --end-of-options pattern..." > > we now see "--end-of-options" listed in .git/info/sparse-checkout as if > it is one of the path patterns. > > A breakage that results from the same cause exists in the check-rules > subcommand, but check-rules has a few other problems that need to be > corrected before it can fully work with --end-of-options safely, > which will be addressed later. > > Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> > --- > builtin/sparse-checkout.c | 3 +++ > parse-options.c | 8 ++++++++ > parse-options.h | 2 ++ > t/t1090-sparse-checkout-scope.sh | 8 ++++++++ > t/t1091-sparse-checkout-builtin.sh | 2 +- > 5 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c > index 5c8ffb1f75..8f55127202 100644 > --- a/builtin/sparse-checkout.c > +++ b/builtin/sparse-checkout.c > @@ -779,6 +779,7 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix) > builtin_sparse_checkout_add_options, > builtin_sparse_checkout_add_usage, > PARSE_OPT_KEEP_UNKNOWN_OPT); > + parse_opt_skip_end_of_options(&argc, &argv); > > sanitize_paths(argc, argv, prefix, add_opts.skip_checks); > > @@ -826,6 +827,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) > builtin_sparse_checkout_set_options, > builtin_sparse_checkout_set_usage, > PARSE_OPT_KEEP_UNKNOWN_OPT); > + parse_opt_skip_end_of_options(&argc, &argv); > > if (update_modes(&set_opts.cone_mode, &set_opts.sparse_index)) > return 1; > @@ -998,6 +1000,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char * > builtin_sparse_checkout_check_rules_options, > builtin_sparse_checkout_check_rules_usage, > PARSE_OPT_KEEP_UNKNOWN_OPT); > + parse_opt_skip_end_of_options(&argc, &argv); > > if (check_rules_opts.rules_file && check_rules_opts.cone_mode < 0) > check_rules_opts.cone_mode = 1; > diff --git a/parse-options.c b/parse-options.c > index d50962062e..fe265bbf68 100644 > --- a/parse-options.c > +++ b/parse-options.c > @@ -1321,3 +1321,11 @@ void die_for_incompatible_opt4(int opt1, const char *opt1_name, > break; > } > } > + > +void parse_opt_skip_end_of_options(int *argc, const char ***argv) > +{ > + if (*argc && !strcmp(**argv, "--end-of-options")) { > + (*argc)--; > + (*argv)++; > + } > +} > diff --git a/parse-options.h b/parse-options.h > index bd62e20268..0d3354d4a8 100644 > --- a/parse-options.h > +++ b/parse-options.h > @@ -498,6 +498,8 @@ int parse_opt_passthru_argv(const struct option *, const char *, int); > /* value is enum branch_track* */ > int parse_opt_tracking_mode(const struct option *, const char *, int); > > +void parse_opt_skip_end_of_options(int *argc, const char ***argv); > + > #define OPT__VERBOSE(var, h) OPT_COUNTUP('v', "verbose", (var), (h)) > #define OPT__QUIET(var, h) OPT_COUNTUP('q', "quiet", (var), (h)) > #define OPT__VERBOSITY(var) { \ > diff --git a/t/t1090-sparse-checkout-scope.sh b/t/t1090-sparse-checkout-scope.sh > index 3a14218b24..5b96716235 100755 > --- a/t/t1090-sparse-checkout-scope.sh > +++ b/t/t1090-sparse-checkout-scope.sh > @@ -57,6 +57,14 @@ test_expect_success 'return to full checkout of main' ' > test_expect_success 'skip-worktree on files outside sparse patterns' ' > git sparse-checkout disable && > git sparse-checkout set --no-cone "a*" && > + cat .git/info/sparse-checkout >wo-eoo && > + > + git sparse-checkout disable && > + git sparse-checkout set --no-cone --end-of-options "a*" && > + cat .git/info/sparse-checkout >w-eoo && > + > + test_cmp wo-eoo w-eoo && > + > git checkout-index --all --ignore-skip-worktree-bits && > > git ls-files -t >output && > diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh > index f67611da28..e33a6ed1b4 100755 > --- a/t/t1091-sparse-checkout-builtin.sh > +++ b/t/t1091-sparse-checkout-builtin.sh > @@ -334,7 +334,7 @@ test_expect_success 'cone mode: set with nested folders' ' > > test_expect_success 'cone mode: add independent path' ' > git -C repo sparse-checkout set deep/deeper1 && > - git -C repo sparse-checkout add folder1 && > + git -C repo sparse-checkout add --end-of-options folder1 && > cat >expect <<-\EOF && > /* > !/*/ > -- > 2.43.0-174-g055bb6e996 I've got a counter-proposal for this patch at https://lore.kernel.org/git/pull.1625.git.git.1703379611749.gitgitgadget@xxxxxxxxx/, based on further thread discussion over at https://lore.kernel.org/git/CABPp-BF9XZeESHdxdcZ91Vsn5tKqQ6_3tC11e7t9vTFp=uufbg@xxxxxxxxxxxxxx/.