Skip to content

Commit d6b38f6

Browse files
pcloudsgitster
authored andcommitted
Add tests for sparse checkout
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a5d07d0 commit d6b38f6

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

t/t1009-read-tree-sparse-checkout.sh

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/bin/sh
2+
3+
test_description='sparse checkout tests'
4+
5+
. ./test-lib.sh
6+
7+
cat >expected <<EOF
8+
100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t
9+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/added
10+
EOF
11+
test_expect_success 'setup' '
12+
test_commit init &&
13+
echo modified >> init.t &&
14+
mkdir sub &&
15+
touch sub/added &&
16+
git add init.t sub/added &&
17+
git commit -m "modified and added" &&
18+
git tag top &&
19+
git rm sub/added &&
20+
git commit -m removed &&
21+
git tag removed &&
22+
git checkout top &&
23+
git ls-files --stage > result &&
24+
test_cmp expected result
25+
'
26+
27+
cat >expected.swt <<EOF
28+
H init.t
29+
H sub/added
30+
EOF
31+
test_expect_success 'read-tree without .git/info/sparse-checkout' '
32+
git read-tree -m -u HEAD &&
33+
git ls-files --stage > result &&
34+
test_cmp expected result &&
35+
git ls-files -t > result &&
36+
test_cmp expected.swt result
37+
'
38+
39+
test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
40+
echo > .git/info/sparse-checkout
41+
git read-tree -m -u HEAD &&
42+
git ls-files -t > result &&
43+
test_cmp expected.swt result &&
44+
test -f init.t &&
45+
test -f sub/added
46+
'
47+
48+
test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
49+
git config core.sparsecheckout true &&
50+
echo > .git/info/sparse-checkout &&
51+
git read-tree --no-sparse-checkout -m -u HEAD &&
52+
git ls-files -t > result &&
53+
test_cmp expected.swt result &&
54+
test -f init.t &&
55+
test -f sub/added
56+
'
57+
58+
cat >expected.swt <<EOF
59+
S init.t
60+
S sub/added
61+
EOF
62+
test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
63+
git config core.sparsecheckout true &&
64+
echo > .git/info/sparse-checkout &&
65+
git read-tree -m -u HEAD &&
66+
git ls-files --stage > result &&
67+
test_cmp expected result &&
68+
git ls-files -t > result &&
69+
test_cmp expected.swt result &&
70+
test ! -f init.t &&
71+
test ! -f sub/added
72+
'
73+
74+
cat >expected.swt <<EOF
75+
S init.t
76+
H sub/added
77+
EOF
78+
test_expect_success 'match directories with trailing slash' '
79+
echo sub/ > .git/info/sparse-checkout &&
80+
git read-tree -m -u HEAD &&
81+
git ls-files -t > result &&
82+
test_cmp expected.swt result &&
83+
test ! -f init.t &&
84+
test -f sub/added
85+
'
86+
87+
cat >expected.swt <<EOF
88+
H init.t
89+
H sub/added
90+
EOF
91+
test_expect_failure 'match directories without trailing slash' '
92+
echo init.t > .git/info/sparse-checkout &&
93+
echo sub >> .git/info/sparse-checkout &&
94+
git read-tree -m -u HEAD &&
95+
git ls-files -t > result &&
96+
test_cmp expected.swt result &&
97+
test ! -f init.t &&
98+
test -f sub/added
99+
'
100+
101+
cat >expected.swt <<EOF
102+
H init.t
103+
S sub/added
104+
EOF
105+
test_expect_success 'checkout area changes' '
106+
echo init.t > .git/info/sparse-checkout &&
107+
git read-tree -m -u HEAD &&
108+
git ls-files -t > result &&
109+
test_cmp expected.swt result &&
110+
test -f init.t &&
111+
test ! -f sub/added
112+
'
113+
114+
test_expect_success 'read-tree updates worktree, absent case' '
115+
echo sub/added > .git/info/sparse-checkout &&
116+
git checkout -f top &&
117+
git read-tree -m -u HEAD^ &&
118+
test ! -f init.t
119+
'
120+
121+
test_expect_success 'read-tree updates worktree, dirty case' '
122+
echo sub/added > .git/info/sparse-checkout &&
123+
git checkout -f top &&
124+
echo dirty > init.t &&
125+
git read-tree -m -u HEAD^ &&
126+
grep -q dirty init.t &&
127+
rm init.t
128+
'
129+
130+
test_expect_success 'read-tree removes worktree, dirty case' '
131+
echo init.t > .git/info/sparse-checkout &&
132+
git checkout -f top &&
133+
echo dirty > added &&
134+
git read-tree -m -u HEAD^ &&
135+
grep -q dirty added
136+
'
137+
138+
test_expect_success 'read-tree adds to worktree, absent case' '
139+
echo init.t > .git/info/sparse-checkout &&
140+
git checkout -f removed &&
141+
git read-tree -u -m HEAD^ &&
142+
test ! -f sub/added
143+
'
144+
145+
test_expect_success 'read-tree adds to worktree, dirty case' '
146+
echo init.t > .git/info/sparse-checkout &&
147+
git checkout -f removed &&
148+
mkdir sub &&
149+
echo dirty > sub/added &&
150+
git read-tree -u -m HEAD^ &&
151+
grep -q dirty sub/added
152+
'
153+
154+
test_done

0 commit comments

Comments
 (0)