3 test_description
='directory traversal handling, especially with common prefixes'
7 test_expect_success
'setup' '
11 mkdir untracked_dir &&
12 >untracked_dir/empty &&
13 git init untracked_repo &&
14 >untracked_repo/empty &&
16 cat <<-EOF >.gitignore &&
20 mkdir an_ignored_dir &&
21 mkdir an_untracked_dir &&
22 >an_ignored_dir/ignored &&
23 >an_ignored_dir/untracked &&
24 >an_untracked_dir/ignored &&
25 >an_untracked_dir/untracked
28 test_expect_success
'git ls-files -o shows the right entries' '
32 an_ignored_dir/ignored
33 an_ignored_dir/untracked
34 an_untracked_dir/ignored
35 an_untracked_dir/untracked
41 git ls-files -o >actual &&
42 test_cmp expect actual
45 test_expect_success
'git ls-files -o --exclude-standard shows the right entries' '
49 an_untracked_dir/untracked
55 git ls-files -o --exclude-standard >actual &&
56 test_cmp expect actual
59 test_expect_success
'git ls-files -o untracked_dir recurses' '
60 echo untracked_dir/empty >expect &&
61 git ls-files -o untracked_dir >actual &&
62 test_cmp expect actual
65 test_expect_success
'git ls-files -o untracked_dir/ recurses' '
66 echo untracked_dir/empty >expect &&
67 git ls-files -o untracked_dir/ >actual &&
68 test_cmp expect actual
71 test_expect_success
'git ls-files -o --directory untracked_dir does not recurse' '
72 echo untracked_dir/ >expect &&
73 git ls-files -o --directory untracked_dir >actual &&
74 test_cmp expect actual
77 test_expect_failure
'git ls-files -o --directory untracked_dir/ does not recurse' '
78 echo untracked_dir/ >expect &&
79 git ls-files -o --directory untracked_dir/ >actual &&
80 test_cmp expect actual
83 test_expect_success
'git ls-files -o untracked_repo does not recurse' '
84 echo untracked_repo/ >expect &&
85 git ls-files -o untracked_repo >actual &&
86 test_cmp expect actual
89 test_expect_failure
'git ls-files -o untracked_repo/ does not recurse' '
90 echo untracked_repo/ >expect &&
91 git ls-files -o untracked_repo/ >actual &&
92 test_cmp expect actual
95 test_expect_success
'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' '
100 git ls-files -o untracked_dir untracked_repo >actual &&
101 test_cmp expect actual
104 test_expect_success
'git ls-files -o untracked_dir/ untracked_repo/ recurses into untracked_dir only' '
105 cat <<-EOF >expect &&
109 git ls-files -o untracked_dir/ untracked_repo/ >actual &&
110 test_cmp expect actual
113 test_expect_success
'git ls-files -o --directory untracked_dir untracked_repo does not recurse' '
114 cat <<-EOF >expect &&
118 git ls-files -o --directory untracked_dir untracked_repo >actual &&
119 test_cmp expect actual
122 test_expect_success
'git ls-files -o --directory untracked_dir/ untracked_repo/ does not recurse' '
123 cat <<-EOF >expect &&
127 git ls-files -o --directory untracked_dir/ untracked_repo/ >actual &&
128 test_cmp expect actual
131 test_expect_success
'git ls-files -o .git shows nothing' '
132 git ls-files -o .git >actual &&
133 test_must_be_empty actual
136 test_expect_failure
'git ls-files -o .git/ shows nothing' '
137 git ls-files -o .git/ >actual &&
138 test_must_be_empty actual
141 test_expect_success FUNNYNAMES
'git ls-files -o untracked_* recurses appropriately' '
142 mkdir "untracked_*" &&
143 >"untracked_*/empty" &&
145 cat <<-EOF >expect &&
150 git ls-files -o "untracked_*" >actual &&
151 test_cmp expect actual
154 # It turns out fill_directory returns the right paths, but ls-files' post-call
155 # filtering in show_dir_entry() via calling dir_path_match() which ends up
156 # in git_fnmatch() has logic for PATHSPEC_ONESTAR that assumes the pathspec
157 # must match the full path; it doesn't check it for matching a leading
159 test_expect_failure FUNNYNAMES
'git ls-files -o untracked_*/ recurses appropriately' '
160 cat <<-EOF >expect &&
165 git ls-files -o "untracked_*/" >actual &&
166 test_cmp expect actual
169 test_expect_success FUNNYNAMES
'git ls-files -o --directory untracked_* does not recurse' '
170 cat <<-EOF >expect &&
175 git ls-files -o --directory "untracked_*" >actual &&
176 test_cmp expect actual
179 test_expect_success FUNNYNAMES
'git ls-files -o --directory untracked_*/ does not recurse' '
180 cat <<-EOF >expect &&
185 git ls-files -o --directory "untracked_*/" >actual &&
186 test_cmp expect actual
189 test_expect_success
'git ls-files -o consistent between one or two dirs' '
190 git ls-files -o --exclude-standard an_ignored_dir/ an_untracked_dir/ >tmp &&
191 ! grep ^an_ignored_dir/ tmp >expect &&
192 git ls-files -o --exclude-standard an_ignored_dir/ >actual &&
193 test_cmp expect actual
196 # ls-files doesn't have a way to request showing both untracked and ignored
197 # files at the same time, so use `git status --ignored`
198 test_expect_failure
'git status --ignored shows same files under dir with or without pathspec' '
199 cat <<-EOF >expect &&
201 !! an_untracked_dir/ignored
203 git status --porcelain --ignored >output &&
204 grep an_untracked_dir output >expect &&
205 git status --porcelain --ignored an_untracked_dir/ >actual &&
206 test_cmp expect actual