git.vger.kernel.org archive mirror
 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 2/3] sparse-checkout: clear patterns when switching modes
Date: Mon, 20 Sep 2021 17:57:37 +0000	[thread overview]
Message-ID: <450b90dad57c42e37a4edc52dac88caf98021fc6.1632160658.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1043.git.1632160658.gitgitgadget@gmail.com>

From: Derrick Stolee <dstolee@microsoft.com>

Previously, when a user runs 'git sparse-checkout init --cone', the
existing patterns would remain, even if the patterns were not in cone
mode. This causes confusion as to how the patterns should work when
later 'git sparse-checkout add' commands append to the pattern list.

In fact, the way these patterns were modified was not even a strict
appending of patterns, but mutating and reordering patterns because of
how the paths were interpreted and rewritten.

As a first step, we shall start overwriting the pattern set completely
when switching to cone mode, unless the existing patterns already match
cone mode patterns. The 'use_cone_patterns' member is set to false if
the patterns fail to parse using cone mode restrictions.

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

diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index b45fd97a98b..fe76c3eedda 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -348,8 +348,17 @@ static int sparse_checkout_init(int argc, const char **argv)
 
 	/* If we already have a sparse-checkout file, use it. */
 	if (res >= 0) {
-		free(sparse_filename);
-		return update_working_directory(NULL);
+		if (pl.use_cone_patterns || !init_opts.cone_mode) {
+			free(sparse_filename);
+			return update_working_directory(NULL);
+		}
+
+		/*
+		 * At this point, note that if res >= 0 but pl.use_cone_patterns
+		 * is false, then we want to override the patterns with the
+		 * initial set of cone mode patterns.
+		 */
+		clear_pattern_list(&pl);
 	}
 
 	if (get_oid("HEAD", &oid)) {
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index a429d2cc671..af0acd32bd9 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -108,7 +108,14 @@ 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
+	git -C bad-patterns sparse-checkout add dir &&
+
+	git -C bad-patterns sparse-checkout init --cone &&
+	cat >expect <<-\EOF &&
+	/*
+	!/*/
+	EOF
+	test_cmp expect bad-patterns/.git/info/sparse-checkout
 '
 
 test_expect_success 'interaction with clone --no-checkout (unborn index)' '
-- 
gitgitgadget


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

Thread overview: 10+ 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 ` Derrick Stolee via GitGitGadget [this message]
2021-09-20 18:52   ` [PATCH 2/3] sparse-checkout: clear patterns when switching modes Taylor Blau
2021-09-20 18:54     ` Taylor Blau
2021-09-20 17:57 ` [PATCH 3/3] sparse-checkout: refuse to add to bad patterns Derrick Stolee via GitGitGadget
2021-09-20 18:59   ` Taylor Blau

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=450b90dad57c42e37a4edc52dac88caf98021fc6.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 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).