Skip to content

Commit f8ab66f

Browse files
newrengitster
authored andcommitted
sparse-checkout: be consistent with end of options markers
9385174 (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 made a previous bug in sparse-checkout more visible; namely, that git sparse-checkout [add|set] --[no-]cone --end-of-options ... would simply treat "--end-of-options" as one of the paths to include in the sparse-checkout. But this was already problematic before; namely, git sparse-checkout [add|set| --[no-]cone --sikp-checks ... would not give an error on the mis-typed "--skip-checks" but instead simply treat "--sikp-checks" as a path or pattern to include in the sparse-checkout, which is highly unfriendly. This behavior began when the command was converted to parse-options in 7bffca9 (sparse-checkout: add '--stdin' option to set subcommand, 2019-11-21). Back then it was just called KEEP_UNKNOWN. Later it was renamed to KEEP_UNKNOWN_OPT in 99d86d6 (parse-options: PARSE_OPT_KEEP_UNKNOWN only applies to --options, 2022-08-19) to clarify that it was only about dashed options; we always keep non-option arguments. Looking at that original patch, both Peff and I think that the author was simply confused about the mis-named option, and really just wanted to keep the non-option arguments. We never should have used the flag all along (and the other cases were cargo-culted within the file). Remove the erroneous PARSE_OPT_KEEP_UNKNOWN_OPT flag now to fix this bug. Note that this does mean that anyone who might have been using git sparse-checkout [add|set] [--[no-]cone] --foo --bar to request paths or patterns '--foo' and '--bar' will now have to use git sparse-checkout [add|set] [--[no-]cone] -- --foo --bar That makes sparse-checkout more consistent with other git commands, provides users much friendlier error messages and behavior, and is consistent with the all-caps warning in git-sparse-checkout.txt that this command "is experimental...its behavior...will likely change". :-) Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e13ed4 commit f8ab66f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

builtin/sparse-checkout.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,7 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
777777

778778
argc = parse_options(argc, argv, prefix,
779779
builtin_sparse_checkout_add_options,
780-
builtin_sparse_checkout_add_usage,
781-
PARSE_OPT_KEEP_UNKNOWN_OPT);
780+
builtin_sparse_checkout_add_usage, 0);
782781

783782
sanitize_paths(argc, argv, prefix, add_opts.skip_checks);
784783

@@ -824,8 +823,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
824823

825824
argc = parse_options(argc, argv, prefix,
826825
builtin_sparse_checkout_set_options,
827-
builtin_sparse_checkout_set_usage,
828-
PARSE_OPT_KEEP_UNKNOWN_OPT);
826+
builtin_sparse_checkout_set_usage, 0);
829827

830828
if (update_modes(&set_opts.cone_mode, &set_opts.sparse_index))
831829
return 1;
@@ -996,8 +994,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char *
996994

997995
argc = parse_options(argc, argv, prefix,
998996
builtin_sparse_checkout_check_rules_options,
999-
builtin_sparse_checkout_check_rules_usage,
1000-
PARSE_OPT_KEEP_UNKNOWN_OPT);
997+
builtin_sparse_checkout_check_rules_usage, 0);
1001998

1002999
if (check_rules_opts.rules_file && check_rules_opts.cone_mode < 0)
10031000
check_rules_opts.cone_mode = 1;

t/t1091-sparse-checkout-builtin.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ test_expect_success 'cone mode: set with nested folders' '
334334

335335
test_expect_success 'cone mode: add independent path' '
336336
git -C repo sparse-checkout set deep/deeper1 &&
337-
git -C repo sparse-checkout add folder1 &&
337+
git -C repo sparse-checkout add --end-of-options folder1 &&
338338
cat >expect <<-\EOF &&
339339
/*
340340
!/*/
@@ -886,6 +886,12 @@ test_expect_success 'by default, cone mode will error out when passed files' '
886886
grep ".gitignore.*is not a directory" error
887887
'
888888

889+
test_expect_success 'error on mistyped command line options' '
890+
test_must_fail git -C repo sparse-checkout add --sikp-checks .gitignore 2>error &&
891+
892+
grep "unknown option.*sikp-checks" error
893+
'
894+
889895
test_expect_success 'by default, non-cone mode will warn on individual files' '
890896
git -C repo sparse-checkout reapply --no-cone &&
891897
git -C repo sparse-checkout add .gitignore 2>warning &&

0 commit comments

Comments
 (0)