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