The eleventh batch
[git/gitster.git] / t / t3000-ls-files-others.sh
blob11af4552f7461e1091e71407517504a6497867e5
1 #!/bin/sh
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
9 filesystem.
11 path0 - a file
12 path1 - a symlink
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
20 . ./test-lib.sh
22 test_expect_success 'setup ' '
23 date >path0 &&
24 if test_have_prereq SYMLINKS
25 then
26 ln -s xyzzy path1
27 else
28 date >path1
29 fi &&
30 mkdir path2 path3 path4 &&
31 date >path2/file2 &&
32 date >path2-junk &&
33 date >path3/file3 &&
34 date >path3-junk &&
35 git update-index --add path3-junk path3/file3
38 test_expect_success 'setup: expected output' '
39 cat >expected1 <<-\EOF &&
40 expected1
41 expected2
42 expected3
43 output
44 path0
45 path1
46 path2-junk
47 path2/file2
48 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' '
78 git init super &&
79 git init sub &&
81 cd sub &&
82 >a &&
83 git add a &&
84 git commit -m sub &&
85 git pack-refs --all
86 ) &&
88 cd super &&
89 "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub &&
90 git ls-files --others --exclude-standard >../actual
91 ) &&
92 echo sub/ >expect &&
93 test_cmp expect actual
96 test_expect_success 'setup nested pathspec search' '
97 test_create_repo nested &&
99 cd 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' '
115 cd nested &&
117 git ls-files -o --directory untracked/deep/ >actual &&
119 cat <<-EOF >expect &&
120 untracked/deep/
123 test_cmp expect actual
127 test_expect_success 'ls-files -o --directory with multiple dir pathspecs' '
129 cd nested &&
131 git ls-files -o --directory partially_tracked/ untracked/ >actual &&
133 cat <<-EOF >expect &&
134 partially_tracked/untracked_dir/
135 untracked/
138 test_cmp expect actual
142 test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' '
144 cd nested &&
146 git ls-files -o --directory partially_tracked/ untracked/deep/path >actual &&
148 cat <<-EOF >expect &&
149 partially_tracked/untracked_dir/
150 untracked/deep/path
153 test_cmp expect actual
157 test_expect_success 'ls-files -o --directory with glob filetype match' '
159 cd nested &&
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/
166 untracked/deep/foo.c
169 test_cmp expect actual
173 test_expect_success 'ls-files -o --directory with mix of tracked states' '
175 cd nested &&
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/
182 untracked/deep/
185 test_cmp expect actual
189 test_expect_success 'ls-files -o --directory with glob filetype match only' '
191 cd nested &&
193 git ls-files --others --directory "untracked/*.c" >actual &&
195 cat <<-EOF >expect &&
196 untracked/deep/foo.c
199 test_cmp expect actual
203 test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' '
205 cd nested &&
207 git ls-files --others --directory "untracked/?*" >actual &&
209 cat <<-EOF >expect &&
210 untracked/deep/
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" &&
220 cd nested &&
222 git init untracked/deep/empty &&
223 git ls-files --others "untracked/*.c" >actual &&
225 cat <<-EOF >expect &&
226 untracked/deep/foo.c
229 test_cmp expect actual
233 test_done