]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-checkout: work with Windows paths
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 11 Feb 2020 15:02:24 +0000 (15:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Feb 2020 17:06:47 +0000 (09:06 -0800)
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>
builtin/sparse-checkout.c
t/t1091-sparse-checkout-builtin.sh

index af9e3e5123b528aa79741d7ba3c637d57bf64c86..3e314e3358223bfd999a0bb966d66efa99c3227b 100644 (file)
@@ -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;
 
index f9265de5e869e0f7d77104f4a2873156f0876c82..c35cbdef454858b943fa30fb58ac59c5694d0065 100755 (executable)
@@ -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