git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] sparse-checkout: work with Windows paths

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 11, 2020, 15:02 UTC
Message-ID
<f770df489849fa8379a9fa18c023bceb788fd96b.1581433344.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.546.git.1581433344.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

When using Windows, a user may run 'git sparse-checkout set A\B\C' to add the Unix-style path A/B/C to their sparse-checkout patterns. Normalizing the input path converts the backslashes to slashes before we add the string 'A/B/C' to the recursive hashset.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 builtin/sparse-checkout.c          |  3 +++
 t/t1091-sparse-checkout-builtin.sh | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index af9e3e5123..3e314e3358 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -394,6 +394,9 @@ static void strbuf_to_cone_pattern(struct strbuf *line, struct pattern_list *pl)
 
 	strbuf_trim_trailing_dir_sep(line);
 
+	if (strbuf_normalize_path(line))
+		die(_("could not normalize path %s"), line->buf);
+
 	if (!line->len)
 		return;
 
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index f9265de5e8..c35cbdef45 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -497,4 +497,18 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
 	test_cmp list-expect list-actual
 '
 
+test_expect_success MINGW 'cone mode replaces backslashes with slashes' '
+	git -C repo sparse-checkout set deep\\deeper1 &&
+	cat >expect <<-\EOF &&
+	/*
+	!/*/
+	/deep/
+	!/deep/*/
+	/deep/deeper1/
+	EOF
+	test_cmp expect repo/.git/info/sparse-checkout &&
+	check_files repo a deep &&
+	check_files repo/deep a deeper1
+'
+
 test_done
-- 
gitgitgadget
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 9 in “Sparse-checkout: Add subcommand and Windows paths”
  1. 0/4 Sparse-checkout: Add subcommand and Windows pathsDerrick Stolee via GitGitGadget, Feb 11, 2020
  2. 2/4 sparse-checkout: extract pattern update from 'set' subcommandDerrick Stolee via GitGitGadget, Feb 11, 2020
  3. 3/4 sparse-checkout: create 'add' subcommandDerrick Stolee via GitGitGadget, Feb 11, 2020
  4. Junio C HamanoFeb 11, 2020
  5. 1/4 sparse-checkout: extract add_patterns_from_input()Derrick Stolee via GitGitGadget, Feb 11, 2020
  6. Junio C HamanoFeb 11, 2020
  7. 4/4 sparse-checkout: work with Windows pathsDerrick Stolee via GitGitGadget, Feb 11, 2020
  8. Junio C HamanoFeb 11, 2020
  9. Jeff KingFeb 11, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.