@matheusbsbs / matheus-bagliano / commits / ef07659926
Fork 0

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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Feb 11, 2020 at 15:02 UTC ef07659926f64d70e8cb41025c3d7456eecb962e
2 files changed +17
builtin/sparse-checkout.c
+3
@@ -394,6 +394,9 @@ static void strbuf_to_cone_pattern(struct strbuf *line, struct pattern_list *pl)
394
395 strbuf_trim_trailing_dir_sep(line);
396
397 + if (strbuf_normalize_path(line))
398 + die(_("could not normalize path %s"), line->buf);
399 +
400 if (!line->len)
401 return;
402
t/t1091-sparse-checkout-builtin.sh
+14
@@ -497,4 +497,18 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
497 test_cmp list-expect list-actual
498 '
499
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 +
514 test_done