Skip to content

Commit f770df4

Browse files
committed
sparse-checkout: work with Windows paths
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 <[email protected]>
1 parent 663c40a commit f770df4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

builtin/sparse-checkout.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ static void strbuf_to_cone_pattern(struct strbuf *line, struct pattern_list *pl)
394394

395395
strbuf_trim_trailing_dir_sep(line);
396396

397+
if (strbuf_normalize_path(line))
398+
die(_("could not normalize path %s"), line->buf);
399+
397400
if (!line->len)
398401
return;
399402

t/t1091-sparse-checkout-builtin.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,18 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
497497
test_cmp list-expect list-actual
498498
'
499499

500+
test_expect_success MINGW 'cone mode replaces backslashes with slashes' '
501+
git -C repo sparse-checkout set deep\\deeper1 &&
502+
cat >expect <<-\EOF &&
503+
/*
504+
!/*/
505+
/deep/
506+
!/deep/*/
507+
/deep/deeper1/
508+
EOF
509+
test_cmp expect repo/.git/info/sparse-checkout &&
510+
check_files repo a deep &&
511+
check_files repo/deep a deeper1
512+
'
513+
500514
test_done

0 commit comments

Comments
 (0)