1#!/bin/sh
2
3test_description='sparse checkout tests
4
5* (tag: removed, master) removed
6| D sub/added
7* (HEAD, tag: top) modified and added
8| M init.t
9| A sub/added
10* (tag: init) init
11 A init.t
12'
13
14. ./test-lib.sh
15
16test_expect_success 'setup' '
17 cat >expected <<-\EOF &&
18 100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t
19 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/added
20 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 subsub/added
21 EOF
22 cat >expected.swt <<-\EOF &&
23 H init.t
24 H sub/added
25 H subsub/added
26 EOF
27
28 test_commit init &&
29 echo modified >>init.t &&
30 mkdir sub subsub &&
31 touch sub/added subsub/added &&
32 git add init.t sub/added subsub/added &&
33 git commit -m "modified and added" &&
34 git tag top &&
35 git rm sub/added &&
36 git commit -m removed &&
37 git tag removed &&
38 git checkout top &&
39 git ls-files --stage >result &&
40 test_cmp expected result
41'
42
43test_expect_success 'read-tree without .git/info/sparse-checkout' '
44 git read-tree -m -u HEAD &&
45 git ls-files --stage >result &&
46 test_cmp expected result &&
47 git ls-files -t >result &&
48 test_cmp expected.swt result
49'
50
51test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
52 echo >.git/info/sparse-checkout &&
53 git read-tree -m -u HEAD &&
54 git ls-files -t >result &&
55 test_cmp expected.swt result &&
56 test -f init.t &&
57 test -f sub/added
58'
59
60test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
61 git config core.sparsecheckout true &&
62 echo >.git/info/sparse-checkout &&
63 git read-tree --no-sparse-checkout -m -u HEAD &&
64 git ls-files -t >result &&
65 test_cmp expected.swt result &&
66 test -f init.t &&
67 test -f sub/added
68'
69
70test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
71 git config core.sparsecheckout true &&
72 echo >.git/info/sparse-checkout &&
73 test_must_fail git read-tree -m -u HEAD &&
74 git ls-files --stage >result &&
75 test_cmp expected result &&
76 git ls-files -t >result &&
77 test_cmp expected.swt result &&
78 test -f init.t &&
79 test -f sub/added
80'
81
82test_expect_success 'match directories with trailing slash' '
83 cat >expected.swt-noinit <<-\EOF &&
84 S init.t
85 H sub/added
86 S subsub/added
87 EOF
88
89 echo sub/ > .git/info/sparse-checkout &&
90 git read-tree -m -u HEAD &&
91 git ls-files -t > result &&
92 test_cmp expected.swt-noinit result &&
93 test ! -f init.t &&
94 test -f sub/added
95'
96
97test_expect_failure 'match directories without trailing slash' '
98 echo init.t >.git/info/sparse-checkout &&
99 echo sub >>.git/info/sparse-checkout &&
100 git read-tree -m -u HEAD &&
101 git ls-files -t >result &&
102 test_cmp expected.swt result &&
103 test ! -f init.t &&
104 test -f sub/added
105'
106
107test_expect_success 'checkout area changes' '
108 cat >expected.swt-nosub <<-\EOF &&
109 H init.t
110 S sub/added
111 S subsub/added
112 EOF
113
114 echo init.t >.git/info/sparse-checkout &&
115 git read-tree -m -u HEAD &&
116 git ls-files -t >result &&
117 test_cmp expected.swt-nosub result &&
118 test -f init.t &&
119 test ! -f sub/added
120'
121
122test_expect_success 'read-tree updates worktree, absent case' '
123 echo sub/added >.git/info/sparse-checkout &&
124 git checkout -f top &&
125 git read-tree -m -u HEAD^ &&
126 test ! -f init.t
127'
128
129test_expect_success 'read-tree updates worktree, dirty case' '
130 echo sub/added >.git/info/sparse-checkout &&
131 git checkout -f top &&
132 echo dirty >init.t &&
133 git read-tree -m -u HEAD^ &&
134 grep -q dirty init.t &&
135 rm init.t
136'
137
138test_expect_success 'read-tree removes worktree, dirty case' '
139 echo init.t >.git/info/sparse-checkout &&
140 git checkout -f top &&
141 echo dirty >added &&
142 git read-tree -m -u HEAD^ &&
143 grep -q dirty added
144'
145
146test_expect_success 'read-tree adds to worktree, absent case' '
147 echo init.t >.git/info/sparse-checkout &&
148 git checkout -f removed &&
149 git read-tree -u -m HEAD^ &&
150 test ! -f sub/added
151'
152
153test_expect_success 'read-tree adds to worktree, dirty case' '
154 echo init.t >.git/info/sparse-checkout &&
155 git checkout -f removed &&
156 mkdir sub &&
157 echo dirty >sub/added &&
158 git read-tree -u -m HEAD^ &&
159 grep -q dirty sub/added
160'
161
162test_expect_success 'index removal and worktree narrowing at the same time' '
163 >empty &&
164 echo init.t >.git/info/sparse-checkout &&
165 echo sub/added >>.git/info/sparse-checkout &&
166 git checkout -f top &&
167 echo init.t >.git/info/sparse-checkout &&
168 git checkout removed &&
169 git ls-files sub/added >result &&
170 test ! -f sub/added &&
171 test_cmp empty result
172'
173
174test_expect_success 'read-tree --reset removes outside worktree' '
175 >empty &&
176 echo init.t >.git/info/sparse-checkout &&
177 git checkout -f top &&
178 git reset --hard removed &&
179 git ls-files sub/added >result &&
180 test_cmp empty result
181'
182
183test_done