Clean up RelNotes for 2.48
[git.git] / t / t3011-common-prefixes-and-directory-traversal.sh
blob69e44c387fa83c576e80854424da694c8afa299c
1 #!/bin/sh
3 test_description='directory traversal handling, especially with common prefixes'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 test_commit hello &&
11 >empty &&
12 mkdir untracked_dir &&
13 >untracked_dir/empty &&
14 git init untracked_repo &&
15 >untracked_repo/empty &&
17 cat <<-EOF >.gitignore &&
18 ignored
19 an_ignored_dir/
20 EOF
21 mkdir an_ignored_dir &&
22 mkdir an_untracked_dir &&
23 >an_ignored_dir/ignored &&
24 >an_ignored_dir/untracked &&
25 >an_untracked_dir/ignored &&
26 >an_untracked_dir/untracked
29 test_expect_success 'git ls-files -o shows the right entries' '
30 cat <<-EOF >expect &&
31 .gitignore
32 actual
33 an_ignored_dir/ignored
34 an_ignored_dir/untracked
35 an_untracked_dir/ignored
36 an_untracked_dir/untracked
37 empty
38 expect
39 untracked_dir/empty
40 untracked_repo/
41 EOF
42 git ls-files -o >actual &&
43 test_cmp expect actual
46 test_expect_success 'git ls-files -o --exclude-standard shows the right entries' '
47 cat <<-EOF >expect &&
48 .gitignore
49 actual
50 an_untracked_dir/untracked
51 empty
52 expect
53 untracked_dir/empty
54 untracked_repo/
55 EOF
56 git ls-files -o --exclude-standard >actual &&
57 test_cmp expect actual
60 test_expect_success 'git ls-files -o untracked_dir recurses' '
61 echo untracked_dir/empty >expect &&
62 git ls-files -o untracked_dir >actual &&
63 test_cmp expect actual
66 test_expect_success 'git ls-files -o untracked_dir/ recurses' '
67 echo untracked_dir/empty >expect &&
68 git ls-files -o untracked_dir/ >actual &&
69 test_cmp expect actual
72 test_expect_success 'git ls-files -o --directory untracked_dir does not recurse' '
73 echo untracked_dir/ >expect &&
74 git ls-files -o --directory untracked_dir >actual &&
75 test_cmp expect actual
78 test_expect_success 'git ls-files -o --directory untracked_dir/ does not recurse' '
79 echo untracked_dir/ >expect &&
80 git ls-files -o --directory untracked_dir/ >actual &&
81 test_cmp expect actual
84 test_expect_success 'git ls-files -o untracked_repo does not recurse' '
85 echo untracked_repo/ >expect &&
86 git ls-files -o untracked_repo >actual &&
87 test_cmp expect actual
90 test_expect_success 'git ls-files -o untracked_repo/ does not recurse' '
91 echo untracked_repo/ >expect &&
92 git ls-files -o untracked_repo/ >actual &&
93 test_cmp expect actual
96 test_expect_success 'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' '
97 cat <<-EOF >expect &&
98 untracked_dir/empty
99 untracked_repo/
101 git ls-files -o untracked_dir untracked_repo >actual &&
102 test_cmp expect actual
105 test_expect_success 'git ls-files -o untracked_dir/ untracked_repo/ recurses into untracked_dir only' '
106 cat <<-EOF >expect &&
107 untracked_dir/empty
108 untracked_repo/
110 git ls-files -o untracked_dir/ untracked_repo/ >actual &&
111 test_cmp expect actual
114 test_expect_success 'git ls-files -o --directory untracked_dir untracked_repo does not recurse' '
115 cat <<-EOF >expect &&
116 untracked_dir/
117 untracked_repo/
119 git ls-files -o --directory untracked_dir untracked_repo >actual &&
120 test_cmp expect actual
123 test_expect_success 'git ls-files -o --directory untracked_dir/ untracked_repo/ does not recurse' '
124 cat <<-EOF >expect &&
125 untracked_dir/
126 untracked_repo/
128 git ls-files -o --directory untracked_dir/ untracked_repo/ >actual &&
129 test_cmp expect actual
132 test_expect_success 'git ls-files -o .git shows nothing' '
133 git ls-files -o .git >actual &&
134 test_must_be_empty actual
137 test_expect_success 'git ls-files -o .git/ shows nothing' '
138 git ls-files -o .git/ >actual &&
139 test_must_be_empty actual
142 test_expect_success FUNNYNAMES 'git ls-files -o untracked_* recurses appropriately' '
143 mkdir "untracked_*" &&
144 >"untracked_*/empty" &&
146 cat <<-EOF >expect &&
147 untracked_*/empty
148 untracked_dir/empty
149 untracked_repo/
151 git ls-files -o "untracked_*" >actual &&
152 test_cmp expect actual
155 # It turns out fill_directory returns the right paths, but ls-files' post-call
156 # filtering in show_dir_entry() via calling dir_path_match() which ends up
157 # in git_fnmatch() has logic for PATHSPEC_ONESTAR that assumes the pathspec
158 # must match the full path; it doesn't check it for matching a leading
159 # directory.
160 test_expect_failure FUNNYNAMES 'git ls-files -o untracked_*/ recurses appropriately' '
161 cat <<-EOF >expect &&
162 untracked_*/empty
163 untracked_dir/empty
164 untracked_repo/
166 git ls-files -o "untracked_*/" >actual &&
167 test_cmp expect actual
170 test_expect_success FUNNYNAMES 'git ls-files -o --directory untracked_* does not recurse' '
171 cat <<-EOF >expect &&
172 untracked_*/
173 untracked_dir/
174 untracked_repo/
176 git ls-files -o --directory "untracked_*" >actual &&
177 test_cmp expect actual
180 test_expect_success FUNNYNAMES 'git ls-files -o --directory untracked_*/ does not recurse' '
181 cat <<-EOF >expect &&
182 untracked_*/
183 untracked_dir/
184 untracked_repo/
186 git ls-files -o --directory "untracked_*/" >actual &&
187 test_cmp expect actual
190 test_expect_success 'git ls-files -o consistent between one or two dirs' '
191 git ls-files -o --exclude-standard an_ignored_dir/ an_untracked_dir/ >tmp &&
192 ! grep ^an_ignored_dir/ tmp >expect &&
193 git ls-files -o --exclude-standard an_ignored_dir/ >actual &&
194 test_cmp expect actual
197 # ls-files doesn't have a way to request showing both untracked and ignored
198 # files at the same time, so use `git status --ignored`
199 test_expect_success 'git status --ignored shows same files under dir with or without pathspec' '
200 cat <<-EOF >expect &&
201 ?? an_untracked_dir/
202 !! an_untracked_dir/ignored
204 git status --porcelain --ignored >output &&
205 grep an_untracked_dir output >expect &&
206 git status --porcelain --ignored an_untracked_dir/ >actual &&
207 test_cmp expect actual
210 test_done