All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, me@ttaylorr.com, calbabreaker@gmail.com,
	Derrick Stolee <derrickstolee@github.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH 3/3] sparse-checkout: refuse to add to bad patterns
Date: Mon, 20 Sep 2021 17:57:38 +0000	[thread overview]
Message-ID: <d513b28b75189d066f9c66de44a1a578cbc38139.1632160658.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1043.git.1632160658.gitgitgadget@gmail.com>

From: Derrick Stolee <dstolee@microsoft.com>

When in cone mode sparse-checkout, it is unclear how 'git
sparse-checkout add <dir1> ...' should behave if the existing
sparse-checkout file does not match the cone mode patterns. Change the
behavior to fail with an error message about the existing patterns.

Also, all cone mode patterns start with a '/' character, so add that
restriction. This is necessary for our example test 'cone mode: warn on
bad pattern', but also requires modifying the example sparse-checkout
file we use to test the warnings related to recognizing cone mode
patterns.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 builtin/sparse-checkout.c          |  3 +++
 dir.c                              |  2 +-
 t/t1091-sparse-checkout-builtin.sh | 11 +++++++----
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index fe76c3eedda..2492ae828a9 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -513,6 +513,9 @@ static void add_patterns_cone_mode(int argc, const char **argv,
 		die(_("unable to load existing sparse-checkout patterns"));
 	free(sparse_filename);
 
+	if (!existing.use_cone_patterns)
+		die(_("existing sparse-checkout patterns do not use cone mode"));
+
 	hashmap_for_each_entry(&existing.recursive_hashmap, &iter, pe, ent) {
 		if (!hashmap_contains_parent(&pl->recursive_hashmap,
 					pe->pattern, &buffer) ||
diff --git a/dir.c b/dir.c
index 03c4d212672..93136442103 100644
--- a/dir.c
+++ b/dir.c
@@ -727,7 +727,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
 	}
 
 	if (given->patternlen < 2 ||
-	    *given->pattern == '*' ||
+	    *given->pattern != '/' ||
 	    strstr(given->pattern, "**")) {
 		/* Not a cone pattern. */
 		warning(_("unrecognized pattern: '%s'"), given->pattern);
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index af0acd32bd9..780c6a1aaae 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -108,14 +108,17 @@ test_expect_success 'switching to cone mode with non-cone mode patterns' '
 	git -C bad-patterns sparse-checkout init &&
 	git -C bad-patterns sparse-checkout add dir &&
 	git -C bad-patterns config core.sparseCheckoutCone true &&
-	git -C bad-patterns sparse-checkout add dir &&
+
+	test_must_fail git -C bad-patterns sparse-checkout add dir 2>err &&
+	grep "existing sparse-checkout patterns do not use cone mode" err &&
 
 	git -C bad-patterns sparse-checkout init --cone &&
 	cat >expect <<-\EOF &&
 	/*
 	!/*/
 	EOF
-	test_cmp expect bad-patterns/.git/info/sparse-checkout
+	test_cmp expect bad-patterns/.git/info/sparse-checkout &&
+	git -C bad-patterns sparse-checkout add dir
 '
 
 test_expect_success 'interaction with clone --no-checkout (unborn index)' '
@@ -182,9 +185,9 @@ test_expect_success 'set sparse-checkout using --stdin' '
 test_expect_success 'add to sparse-checkout' '
 	cat repo/.git/info/sparse-checkout >expect &&
 	cat >add <<-\EOF &&
-	pattern1
+	/pattern1
 	/folder1/
-	pattern2
+	/pattern2
 	EOF
 	cat add >>expect &&
 	git -C repo sparse-checkout add --stdin <add &&
-- 
gitgitgadget

  parent reply	other threads:[~2021-09-21  0:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 17:57 [PATCH 0/3] Sparse checkout: fix mixed-mode pattern issues Derrick Stolee via GitGitGadget
2021-09-20 17:57 ` [PATCH 1/3] sparse-checkout: fix OOM error with mixed patterns Derrick Stolee via GitGitGadget
2021-09-20 18:24   ` Taylor Blau
2021-09-21 13:06     ` Derrick Stolee
2021-09-21 16:35       ` Taylor Blau
2021-09-20 17:57 ` [PATCH 2/3] sparse-checkout: clear patterns when switching modes Derrick Stolee via GitGitGadget
2021-09-20 18:52   ` Taylor Blau
2021-09-20 18:54     ` Taylor Blau
2021-09-20 17:57 ` Derrick Stolee via GitGitGadget [this message]
2021-09-20 18:59   ` [PATCH 3/3] sparse-checkout: refuse to add to bad patterns Taylor Blau
2021-12-07 20:02 [PATCH 0/3] sparse-checkout: fix segfault on malformed patterns Derrick Stolee via GitGitGadget
2021-12-07 20:02 ` [PATCH 3/3] sparse-checkout: refuse to add to bad patterns Derrick Stolee via GitGitGadget

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=d513b28b75189d066f9c66de44a1a578cbc38139.1632160658.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=calbabreaker@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.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.