3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='basic tests for ls-files --others
8 This test runs git ls-files --others with the following on the
13 path2/file2 - a file in a directory
14 path3-junk - a file to confuse things
15 path3/file3 - a file in a directory
16 path4 - an empty directory
19 TEST_PASSES_SANITIZE_LEAK
=true
22 test_expect_success
'setup ' '
24 if test_have_prereq SYMLINKS
30 mkdir path2 path3 path4 &&
35 git update-index --add path3-junk path3/file3
38 test_expect_success
'setup: expected output' '
39 cat >expected1 <<-\EOF &&
50 sed -e "s|path2/file2|path2/|" <expected1 >expected2 &&
51 cp expected2 expected3 &&
52 echo path4/ >>expected2
55 test_expect_success
'ls-files --others' '
56 git ls-files --others >output &&
57 test_cmp expected1 output
60 test_expect_success
'ls-files --others --directory' '
61 git ls-files --others --directory >output &&
62 test_cmp expected2 output
65 test_expect_success
'--no-empty-directory hides empty directory' '
66 git ls-files --others --directory --no-empty-directory >output &&
67 test_cmp expected3 output
70 test_expect_success
'ls-files --others handles non-submodule .git' '
71 mkdir not-a-submodule &&
72 echo foo >not-a-submodule/.git &&
73 git ls-files -o >output &&
74 test_cmp expected1 output
77 test_expect_success SYMLINKS
'ls-files --others with symlinked submodule' '
89 "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub &&
90 git ls-files --others --exclude-standard >../actual
93 test_cmp expect actual
96 test_expect_success
'setup nested pathspec search' '
97 test_create_repo nested &&
101 mkdir -p partially_tracked/untracked_dir &&
102 > partially_tracked/content &&
103 > partially_tracked/untracked_dir/file &&
105 mkdir -p untracked/deep &&
106 > untracked/deep/path &&
107 > untracked/deep/foo.c &&
109 git add partially_tracked/content
113 test_expect_success
'ls-files -o --directory with single deep dir pathspec' '
117 git ls-files -o --directory untracked/deep/ >actual &&
119 cat <<-EOF >expect &&
123 test_cmp expect actual
127 test_expect_success
'ls-files -o --directory with multiple dir pathspecs' '
131 git ls-files -o --directory partially_tracked/ untracked/ >actual &&
133 cat <<-EOF >expect &&
134 partially_tracked/untracked_dir/
138 test_cmp expect actual
142 test_expect_success
'ls-files -o --directory with mix dir/file pathspecs' '
146 git ls-files -o --directory partially_tracked/ untracked/deep/path >actual &&
148 cat <<-EOF >expect &&
149 partially_tracked/untracked_dir/
153 test_cmp expect actual
157 test_expect_success
'ls-files -o --directory with glob filetype match' '
161 # globs kinda defeat --directory, but only for that pathspec
162 git ls-files --others --directory partially_tracked "untracked/*.c" >actual &&
164 cat <<-EOF >expect &&
165 partially_tracked/untracked_dir/
169 test_cmp expect actual
173 test_expect_success
'ls-files -o --directory with mix of tracked states' '
177 # globs kinda defeat --directory, but only for that pathspec
178 git ls-files --others --directory partially_tracked/ "untracked/?*" >actual &&
180 cat <<-EOF >expect &&
181 partially_tracked/untracked_dir/
185 test_cmp expect actual
189 test_expect_success
'ls-files -o --directory with glob filetype match only' '
193 git ls-files --others --directory "untracked/*.c" >actual &&
195 cat <<-EOF >expect &&
199 test_cmp expect actual
203 test_expect_success
'ls-files -o --directory to get immediate paths under one dir only' '
207 git ls-files --others --directory "untracked/?*" >actual &&
209 cat <<-EOF >expect &&
213 test_cmp expect actual
217 test_expect_success
'ls-files -o avoids listing untracked non-matching gitdir' '
218 test_when_finished "rm -rf nested/untracked/deep/empty" &&
222 git init untracked/deep/empty &&
223 git ls-files --others "untracked/*.c" >actual &&
225 cat <<-EOF >expect &&
229 test_cmp expect actual