Skip to content

Commit 761e3d2

Browse files
emastegitster
authored andcommitted
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 <[email protected]> Helped-by: Junio C Hamano <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Ed Maste <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 190a65f commit 761e3d2

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

t/t1091-sparse-checkout-builtin.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ test_description='sparse checkout builtin tests'
44

55
. ./test-lib.sh
66

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+
715
test_expect_success 'setup' '
816
git init repo &&
917
(
@@ -50,7 +58,7 @@ test_expect_success 'git sparse-checkout init' '
5058
EOF
5159
test_cmp expect repo/.git/info/sparse-checkout &&
5260
test_cmp_config -C repo true core.sparsecheckout &&
53-
ls repo >dir &&
61+
list_files repo >dir &&
5462
echo a >expect &&
5563
test_cmp expect dir
5664
'
@@ -73,7 +81,7 @@ test_expect_success 'init with existing sparse-checkout' '
7381
*folder*
7482
EOF
7583
test_cmp expect repo/.git/info/sparse-checkout &&
76-
ls repo >dir &&
84+
list_files repo >dir &&
7785
cat >expect <<-EOF &&
7886
a
7987
folder1
@@ -90,7 +98,7 @@ test_expect_success 'clone --sparse' '
9098
!/*/
9199
EOF
92100
test_cmp expect actual &&
93-
ls clone >dir &&
101+
list_files clone >dir &&
94102
echo a >expect &&
95103
test_cmp expect dir
96104
'
@@ -119,7 +127,7 @@ test_expect_success 'set sparse-checkout using builtin' '
119127
git -C repo sparse-checkout list >actual &&
120128
test_cmp expect actual &&
121129
test_cmp expect repo/.git/info/sparse-checkout &&
122-
ls repo >dir &&
130+
list_files repo >dir &&
123131
cat >expect <<-EOF &&
124132
a
125133
folder1
@@ -139,7 +147,7 @@ test_expect_success 'set sparse-checkout using --stdin' '
139147
git -C repo sparse-checkout list >actual &&
140148
test_cmp expect actual &&
141149
test_cmp expect repo/.git/info/sparse-checkout &&
142-
ls repo >dir &&
150+
list_files repo >dir &&
143151
cat >expect <<-EOF &&
144152
a
145153
folder1
@@ -154,7 +162,7 @@ test_expect_success 'cone mode: match patterns' '
154162
git -C repo read-tree -mu HEAD 2>err &&
155163
test_i18ngrep ! "disabling cone patterns" err &&
156164
git -C repo reset --hard &&
157-
ls repo >dir &&
165+
list_files repo >dir &&
158166
cat >expect <<-EOF &&
159167
a
160168
folder1
@@ -177,7 +185,7 @@ test_expect_success 'sparse-checkout disable' '
177185
test_path_is_file repo/.git/info/sparse-checkout &&
178186
git -C repo config --list >config &&
179187
test_must_fail git config core.sparseCheckout &&
180-
ls repo >dir &&
188+
list_files repo >dir &&
181189
cat >expect <<-EOF &&
182190
a
183191
deep
@@ -191,24 +199,24 @@ test_expect_success 'cone mode: init and set' '
191199
git -C repo sparse-checkout init --cone &&
192200
git -C repo config --list >config &&
193201
test_i18ngrep "core.sparsecheckoutcone=true" config &&
194-
ls repo >dir &&
202+
list_files repo >dir &&
195203
echo a >expect &&
196204
test_cmp expect dir &&
197205
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
198206
test_must_be_empty err &&
199-
ls repo >dir &&
207+
list_files repo >dir &&
200208
cat >expect <<-EOF &&
201209
a
202210
deep
203211
EOF
204212
test_cmp expect dir &&
205-
ls repo/deep >dir &&
213+
list_files repo/deep >dir &&
206214
cat >expect <<-EOF &&
207215
a
208216
deeper1
209217
EOF
210218
test_cmp expect dir &&
211-
ls repo/deep/deeper1 >dir &&
219+
list_files repo/deep/deeper1 >dir &&
212220
cat >expect <<-EOF &&
213221
a
214222
deepest
@@ -234,7 +242,7 @@ test_expect_success 'cone mode: init and set' '
234242
folder1
235243
folder2
236244
EOF
237-
ls repo >dir &&
245+
list_files repo >dir &&
238246
test_cmp expect dir
239247
'
240248

@@ -256,7 +264,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' '
256264
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
257265
test_i18ngrep "cannot set sparse-checkout patterns" err &&
258266
test_cmp repo/.git/info/sparse-checkout expect &&
259-
ls repo/deep >dir &&
267+
list_files repo/deep >dir &&
260268
cat >expect <<-EOF &&
261269
a
262270
deeper1
@@ -313,7 +321,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '
313321
/folder1/
314322
EOF
315323
test_cmp expect repo/.git/info/sparse-checkout &&
316-
ls repo >dir &&
324+
list_files repo >dir &&
317325
cat >expect <<-EOF &&
318326
a
319327
folder1

0 commit comments

Comments
 (0)