Use the final_oid_fn to finalize hashing of object IDs
[alt-git.git] / t / t3000-ls-files-others.sh
blob740ce56eab5c78b18a85834e9dc9c091d195c2d1
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
18 . ./test-lib.sh
20 test_expect_success 'setup ' '
21 date >path0 &&
22 if test_have_prereq SYMLINKS
23 then
24 ln -s xyzzy path1
25 else
26 date >path1
27 fi &&
28 mkdir path2 path3 path4 &&
29 date >path2/file2 &&
30 date >path2-junk &&
31 date >path3/file3 &&
32 date >path3-junk &&
33 git update-index --add path3-junk path3/file3
36 test_expect_success 'setup: expected output' '
37 cat >expected1 <<-\EOF &&
38 expected1
39 expected2
40 expected3
41 output
42 path0
43 path1
44 path2-junk
45 path2/file2
46 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' '
76 git init super &&
77 git init sub &&
79 cd sub &&
80 >a &&
81 git add a &&
82 git commit -m sub &&
83 git pack-refs --all
84 ) &&
86 cd super &&
87 "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub &&
88 git ls-files --others --exclude-standard >../actual
89 ) &&
90 echo sub/ >expect &&
91 test_cmp expect actual
94 test_expect_success 'setup nested pathspec search' '
95 test_create_repo nested &&
97 cd 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' '
113 cd nested &&
115 git ls-files -o --directory untracked/deep/ >actual &&
117 cat <<-EOF >expect &&
118 untracked/deep/
121 test_cmp expect actual
125 test_expect_success 'ls-files -o --directory with multiple dir pathspecs' '
127 cd nested &&
129 git ls-files -o --directory partially_tracked/ untracked/ >actual &&
131 cat <<-EOF >expect &&
132 partially_tracked/untracked_dir/
133 untracked/
136 test_cmp expect actual
140 test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' '
142 cd nested &&
144 git ls-files -o --directory partially_tracked/ untracked/deep/path >actual &&
146 cat <<-EOF >expect &&
147 partially_tracked/untracked_dir/
148 untracked/deep/path
151 test_cmp expect actual
155 test_expect_success 'ls-files -o --directory with glob filetype match' '
157 cd nested &&
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/
164 untracked/deep/foo.c
167 test_cmp expect actual
171 test_expect_success 'ls-files -o --directory with mix of tracked states' '
173 cd nested &&
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/
180 untracked/deep/
183 test_cmp expect actual
187 test_expect_success 'ls-files -o --directory with glob filetype match only' '
189 cd nested &&
191 git ls-files --others --directory "untracked/*.c" >actual &&
193 cat <<-EOF >expect &&
194 untracked/deep/foo.c
197 test_cmp expect actual
201 test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' '
203 cd nested &&
205 git ls-files --others --directory "untracked/?*" >actual &&
207 cat <<-EOF >expect &&
208 untracked/deep/
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" &&
218 cd nested &&
220 git init untracked/deep/empty &&
221 git ls-files --others "untracked/*.c" >actual &&
223 cat <<-EOF >expect &&
224 untracked/deep/foo.c
227 test_cmp expect actual
231 test_done