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
20 test_expect_success
'setup ' '
22 if test_have_prereq SYMLINKS
28 mkdir path2 path3 path4 &&
33 git update-index --add path3-junk path3/file3
36 test_expect_success
'setup: expected output' '
37 cat >expected1 <<-\EOF &&
48 sed -e "s|path2/file2|path2/|" <expected1 >expected2 &&
49 cp expected2 expected3 &&
50 echo path4/ >>expected2
53 test_expect_success
'ls-files --others' '
54 git ls-files --others >output &&
55 test_cmp expected1 output
58 test_expect_success
'ls-files --others --directory' '
59 git ls-files --others --directory >output &&
60 test_cmp expected2 output
63 test_expect_success
'--no-empty-directory hides empty directory' '
64 git ls-files --others --directory --no-empty-directory >output &&
65 test_cmp expected3 output
68 test_expect_success
'ls-files --others handles non-submodule .git' '
69 mkdir not-a-submodule &&
70 echo foo >not-a-submodule/.git &&
71 git ls-files -o >output &&
72 test_cmp expected1 output
75 test_expect_success SYMLINKS
'ls-files --others with symlinked submodule' '
87 "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub &&
88 git ls-files --others --exclude-standard >../actual
91 test_cmp expect actual
94 test_expect_success
'setup nested pathspec search' '
95 test_create_repo nested &&
99 mkdir -p partially_tracked/untracked_dir &&
100 > partially_tracked/content &&
101 > partially_tracked/untracked_dir/file &&
103 mkdir -p untracked/deep &&
104 > untracked/deep/path &&
105 > untracked/deep/foo.c &&
107 git add partially_tracked/content
111 test_expect_success
'ls-files -o --directory with single deep dir pathspec' '
115 git ls-files -o --directory untracked/deep/ >actual &&
117 cat <<-EOF >expect &&
121 test_cmp expect actual
125 test_expect_success
'ls-files -o --directory with multiple dir pathspecs' '
129 git ls-files -o --directory partially_tracked/ untracked/ >actual &&
131 cat <<-EOF >expect &&
132 partially_tracked/untracked_dir/
136 test_cmp expect actual
140 test_expect_success
'ls-files -o --directory with mix dir/file pathspecs' '
144 git ls-files -o --directory partially_tracked/ untracked/deep/path >actual &&
146 cat <<-EOF >expect &&
147 partially_tracked/untracked_dir/
151 test_cmp expect actual
155 test_expect_success
'ls-files -o --directory with glob filetype match' '
159 # globs kinda defeat --directory, but only for that pathspec
160 git ls-files --others --directory partially_tracked "untracked/*.c" >actual &&
162 cat <<-EOF >expect &&
163 partially_tracked/untracked_dir/
167 test_cmp expect actual
171 test_expect_success
'ls-files -o --directory with mix of tracked states' '
175 # globs kinda defeat --directory, but only for that pathspec
176 git ls-files --others --directory partially_tracked/ "untracked/?*" >actual &&
178 cat <<-EOF >expect &&
179 partially_tracked/untracked_dir/
183 test_cmp expect actual
187 test_expect_success
'ls-files -o --directory with glob filetype match only' '
191 git ls-files --others --directory "untracked/*.c" >actual &&
193 cat <<-EOF >expect &&
197 test_cmp expect actual
201 test_expect_success
'ls-files -o --directory to get immediate paths under one dir only' '
205 git ls-files --others --directory "untracked/?*" >actual &&
207 cat <<-EOF >expect &&
211 test_cmp expect actual
215 test_expect_success
'ls-files -o avoids listing untracked non-matching gitdir' '
216 test_when_finished "rm -rf nested/untracked/deep/empty" &&
220 git init untracked/deep/empty &&
221 git ls-files --others "untracked/*.c" >actual &&
223 cat <<-EOF >expect &&
227 test_cmp expect actual