From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Derrick Stolee <stolee@gmail.com>, William Sprent <williams@unity3d.com>
Subject: [PATCH 3/3] sparse-checkout: tighten add_patterns_from_input()
Date: Wed, 20 Dec 2023 22:59:25 -0800 [thread overview]
Message-ID: <20231221065925.3234048-4-gitster@pobox.com> (raw)
In-Reply-To: <20231221065925.3234048-1-gitster@pobox.com>
The add_patterns_from_input() function was introduced at 6fb705ab
(sparse-checkout: extract add_patterns_from_input(), 2020-02-11) and
then modified by 00408ade (builtin/sparse-checkout: add check-rules
command, 2023-03-27). Throughout its life, it either allowed to
read patterns from the file (before 00408ade, it only allowed the
standard input, after 00408ade, an arbitrary FILE *) or from argv[],
but never both. However, when we read from a file, the function
never checked that there is nothing in argv[] (in other words, the
command line arguments have fully been consumed), resulting in
excess arguments silently getting ignored.
This caused commands like "git sparse-checkout set [--stdin]" and
"git sparse-checkout check-rules [--rules-file <file>]" to silently
ignore the rest of the command line arguments without reporting.
The fix finally makes the --end-of-options handling for this
subcommand also work, so add test for it, too.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/sparse-checkout.c | 4 ++++
t/t1091-sparse-checkout-builtin.sh | 11 ++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 04ae81fce8..1166e1e298 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -555,6 +555,10 @@ static void add_patterns_from_input(struct pattern_list *pl,
FILE *file)
{
int i;
+
+ if (file && argc)
+ die(_("excess command line parameter '%s'"), argv[0]);
+
if (core_sparse_checkout_cone) {
struct strbuf line = STRBUF_INIT;
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index e33a6ed1b4..107ed170ac 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -937,6 +937,10 @@ test_expect_success 'check-rules cone mode' '
EOF
git -C bare ls-tree -r --name-only HEAD >all-files &&
+
+ test_must_fail git -C bare sparse-checkout check-rules --cone \
+ --rules-file ../rules excess args <all-files &&
+
git -C bare sparse-checkout check-rules --cone \
--rules-file ../rules >check-rules-file <all-files &&
@@ -947,6 +951,7 @@ test_expect_success 'check-rules cone mode' '
git -C repo sparse-checkout check-rules >check-rules-default <all-files &&
test_grep "deep/deeper1/deepest/a" check-rules-file &&
+ test_grep ! "end-of-options" check-rules-file &&
test_grep ! "deep/deeper2" check-rules-file &&
test_cmp check-rules-file ls-files &&
@@ -959,8 +964,12 @@ test_expect_success 'check-rules non-cone mode' '
EOF
git -C bare ls-tree -r --name-only HEAD >all-files &&
+
+ test_must_fail git -C bare sparse-checkout check-rules --no-cone \
+ --rules-file ../rules excess args <all-files &&
+
git -C bare sparse-checkout check-rules --no-cone --rules-file ../rules\
- >check-rules-file <all-files &&
+ --end-of-options >check-rules-file <all-files &&
cat rules | git -C repo sparse-checkout set --no-cone --stdin &&
git -C repo ls-files -t >out &&
--
2.43.0-174-g055bb6e996
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 ` [PATCH 1/3] sparse-checkout: take care of "--end-of-options" in set/add/check-rules Junio C Hamano
2023-12-24 7:53 ` 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 ` Junio C Hamano [this message]
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-4-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=stolee@gmail.com \
--cc=williams@unity3d.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.