clone: add --sparse mode
[git] / t / t1091-sparse-checkout-builtin.sh
1 #!/bin/sh
2
3 test_description='sparse checkout builtin tests'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8         git init repo &&
9         (
10                 cd repo &&
11                 echo "initial" >a &&
12                 mkdir folder1 folder2 deep &&
13                 mkdir deep/deeper1 deep/deeper2 &&
14                 mkdir deep/deeper1/deepest &&
15                 cp a folder1 &&
16                 cp a folder2 &&
17                 cp a deep &&
18                 cp a deep/deeper1 &&
19                 cp a deep/deeper2 &&
20                 cp a deep/deeper1/deepest &&
21                 git add . &&
22                 git commit -m "initial commit"
23         )
24 '
25
26 test_expect_success 'git sparse-checkout list (empty)' '
27         git -C repo sparse-checkout list >list 2>err &&
28         test_must_be_empty list &&
29         test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
30 '
31
32 test_expect_success 'git sparse-checkout list (populated)' '
33         test_when_finished rm -f repo/.git/info/sparse-checkout &&
34         cat >repo/.git/info/sparse-checkout <<-EOF &&
35                 /folder1/*
36                 /deep/
37                 **/a
38                 !*bin*
39         EOF
40         cp repo/.git/info/sparse-checkout expect &&
41         git -C repo sparse-checkout list >list &&
42         test_cmp expect list
43 '
44
45 test_expect_success 'git sparse-checkout init' '
46         git -C repo sparse-checkout init &&
47         cat >expect <<-EOF &&
48                 /*
49                 !/*/
50         EOF
51         test_cmp expect repo/.git/info/sparse-checkout &&
52         test_cmp_config -C repo true core.sparsecheckout &&
53         ls repo >dir  &&
54         echo a >expect &&
55         test_cmp expect dir
56 '
57
58 test_expect_success 'git sparse-checkout list after init' '
59         git -C repo sparse-checkout list >actual &&
60         cat >expect <<-EOF &&
61                 /*
62                 !/*/
63         EOF
64         test_cmp expect actual
65 '
66
67 test_expect_success 'init with existing sparse-checkout' '
68         echo "*folder*" >> repo/.git/info/sparse-checkout &&
69         git -C repo sparse-checkout init &&
70         cat >expect <<-EOF &&
71                 /*
72                 !/*/
73                 *folder*
74         EOF
75         test_cmp expect repo/.git/info/sparse-checkout &&
76         ls repo >dir  &&
77         cat >expect <<-EOF &&
78                 a
79                 folder1
80                 folder2
81         EOF
82         test_cmp expect dir
83 '
84
85 test_expect_success 'clone --sparse' '
86         git clone --sparse repo clone &&
87         git -C clone sparse-checkout list >actual &&
88         cat >expect <<-EOF &&
89                 /*
90                 !/*/
91         EOF
92         test_cmp expect actual &&
93         ls clone >dir &&
94         echo a >expect &&
95         test_cmp expect dir
96 '
97
98 test_done