sparse-checkout: improve OS ls compatibility
On FreeBSD, when executed by root ls enables the '-A' option: -A Include directory entries whose names begin with a dot (`.') except for . and ... Automatically set for the super-user unless -I is specified. As a result the .git directory appeared in the output when run as root. Simulate no-dotfile ls behaviour using a shell glob. Helped-by: Eric Wong <e@80x24.org> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Ed Maste <emaste@FreeBSD.org> Acked-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ed Maste committed
Dec 20, 2019 at 19:41 UTC
761e3d26bbe44c51f83c4f1ad198461f57029ebd
1 file changed
+22
-14
t/t1091-sparse-checkout-builtin.sh
+22
-14
@@ -4,6 +4,14 @@ test_description='sparse checkout builtin tests'
4
5
. ./test-lib.sh
6
7
+list_files() {
8
+ # Do not replace this with 'ls "$1"', as "ls" with BSD-lineage
9
+ # enables "-A" by default for root and ends up including ".git" and
10
+ # such in its output. (Note, though, that running the test suite as
11
+ # root is generally not recommended.)
12
+ (cd "$1" && printf '%s\n' *)
13
+}
14
+
15
test_expect_success 'setup' '
16
git init repo &&
17
(
@@ -50,7 +58,7 @@ test_expect_success 'git sparse-checkout init' '
58
EOF
59
test_cmp expect repo/.git/info/sparse-checkout &&
60
test_cmp_config -C repo true core.sparsecheckout &&
53
- ls repo >dir &&
61
+ list_files repo >dir &&
62
echo a >expect &&
63
test_cmp expect dir
64
'
@@ -73,7 +81,7 @@ test_expect_success 'init with existing sparse-checkout' '
81
*folder*
82
EOF
83
test_cmp expect repo/.git/info/sparse-checkout &&
76
- ls repo >dir &&
84
+ list_files repo >dir &&
85
cat >expect <<-EOF &&
86
a
87
folder1
@@ -90,7 +98,7 @@ test_expect_success 'clone --sparse' '
98
!/*/
99
EOF
100
test_cmp expect actual &&
93
- ls clone >dir &&
101
+ list_files clone >dir &&
102
echo a >expect &&
103
test_cmp expect dir
104
'
@@ -119,7 +127,7 @@ test_expect_success 'set sparse-checkout using builtin' '
127
git -C repo sparse-checkout list >actual &&
128
test_cmp expect actual &&
129
test_cmp expect repo/.git/info/sparse-checkout &&
122
- ls repo >dir &&
130
+ list_files repo >dir &&
131
cat >expect <<-EOF &&
132
a
133
folder1
@@ -139,7 +147,7 @@ test_expect_success 'set sparse-checkout using --stdin' '
147
git -C repo sparse-checkout list >actual &&
148
test_cmp expect actual &&
149
test_cmp expect repo/.git/info/sparse-checkout &&
142
- ls repo >dir &&
150
+ list_files repo >dir &&
151
cat >expect <<-EOF &&
152
a
153
folder1
@@ -154,7 +162,7 @@ test_expect_success 'cone mode: match patterns' '
162
git -C repo read-tree -mu HEAD 2>err &&
163
test_i18ngrep ! "disabling cone patterns" err &&
164
git -C repo reset --hard &&
157
- ls repo >dir &&
165
+ list_files repo >dir &&
166
cat >expect <<-EOF &&
167
a
168
folder1
@@ -177,7 +185,7 @@ test_expect_success 'sparse-checkout disable' '
185
test_path_is_file repo/.git/info/sparse-checkout &&
186
git -C repo config --list >config &&
187
test_must_fail git config core.sparseCheckout &&
180
- ls repo >dir &&
188
+ list_files repo >dir &&
189
cat >expect <<-EOF &&
190
a
191
deep
@@ -191,24 +199,24 @@ test_expect_success 'cone mode: init and set' '
199
git -C repo sparse-checkout init --cone &&
200
git -C repo config --list >config &&
201
test_i18ngrep "core.sparsecheckoutcone=true" config &&
194
- ls repo >dir &&
202
+ list_files repo >dir &&
203
echo a >expect &&
204
test_cmp expect dir &&
205
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
206
test_must_be_empty err &&
199
- ls repo >dir &&
207
+ list_files repo >dir &&
208
cat >expect <<-EOF &&
209
a
210
deep
211
EOF
212
test_cmp expect dir &&
205
- ls repo/deep >dir &&
213
+ list_files repo/deep >dir &&
214
cat >expect <<-EOF &&
215
a
216
deeper1
217
EOF
218
test_cmp expect dir &&
211
- ls repo/deep/deeper1 >dir &&
219
+ list_files repo/deep/deeper1 >dir &&
220
cat >expect <<-EOF &&
221
a
222
deepest
@@ -234,7 +242,7 @@ test_expect_success 'cone mode: init and set' '
242
folder1
243
folder2
244
EOF
237
- ls repo >dir &&
245
+ list_files repo >dir &&
246
test_cmp expect dir
247
'
248
@@ -256,7 +264,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' '
264
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
265
test_i18ngrep "cannot set sparse-checkout patterns" err &&
266
test_cmp repo/.git/info/sparse-checkout expect &&
259
- ls repo/deep >dir &&
267
+ list_files repo/deep >dir &&
268
cat >expect <<-EOF &&
269
a
270
deeper1
@@ -313,7 +321,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '
321
/folder1/
322
EOF
323
test_cmp expect repo/.git/info/sparse-checkout &&
316
- ls repo >dir &&
324
+ list_files repo >dir &&
325
cat >expect <<-EOF &&
326
a
327
folder1