From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Josh Steadmon <steadmon@google.com>
Subject: [PATCH 1/3] sparse-checkout: take care of "--end-of-options" in set/add/check-rules
Date: Wed, 20 Dec 2023 22:59:23 -0800 [thread overview]
Message-ID: <20231221065925.3234048-2-gitster@pobox.com> (raw)
In-Reply-To: <20231221065925.3234048-1-gitster@pobox.com>
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@pobox.com>
---
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
next prev parent reply other threads:[~2023-12-21 6:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-21 6:59 [PATCH 0/3] sparse-checkout with --end-of-options Junio C Hamano
2023-12-21 6:59 ` Junio C Hamano [this message]
2023-12-24 7:53 ` [PATCH 1/3] sparse-checkout: take care of "--end-of-options" in set/add/check-rules Elijah Newren
2023-12-21 6:59 ` [PATCH 2/3] sparse-checkout: use default patterns for 'set' only !stdin Junio C Hamano
2023-12-24 7:51 ` Elijah Newren
2023-12-28 0:18 ` Junio C Hamano
2023-12-21 6:59 ` [PATCH 3/3] sparse-checkout: tighten add_patterns_from_input() Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231221065925.3234048-2-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=steadmon@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).