read-tree: narrow scope of index expansion for '--prefix'
[alt-git.git] / t / t3011-common-prefixes-and-directory-traversal.sh
blob3da5b2b6e795ec4587608ead8bc10abf0c6d9039
1 #!/bin/sh
3 test_description='directory traversal handling, especially with common prefixes'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit hello &&
10 >empty &&
11 mkdir untracked_dir &&
12 >untracked_dir/empty &&
13 git init untracked_repo &&
14 >untracked_repo/empty &&
16 cat <<-EOF >.gitignore &&
17 ignored
18 an_ignored_dir/
19 EOF
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' '
29 cat <<-EOF >expect &&
30 .gitignore
31 actual
32 an_ignored_dir/ignored
33 an_ignored_dir/untracked
34 an_untracked_dir/ignored
35 an_untracked_dir/untracked
36 empty
37 expect
38 untracked_dir/empty
39 untracked_repo/
40 EOF
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' '
46 cat <<-EOF >expect &&
47 .gitignore
48 actual
49 an_untracked_dir/untracked
50 empty
51 expect
52 untracked_dir/empty
53 untracked_repo/
54 EOF
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_success '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_success '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' '
96 cat <<-EOF >expect &&
97 untracked_dir/empty
98 untracked_repo/
99 EOF
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 &&
106 untracked_dir/empty
107 untracked_repo/
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 &&
115 untracked_dir/
116 untracked_repo/
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 &&
124 untracked_dir/
125 untracked_repo/
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_success '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 &&
146 untracked_*/empty
147 untracked_dir/empty
148 untracked_repo/
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
158 # directory.
159 test_expect_failure FUNNYNAMES 'git ls-files -o untracked_*/ recurses appropriately' '
160 cat <<-EOF >expect &&
161 untracked_*/empty
162 untracked_dir/empty
163 untracked_repo/
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 &&
171 untracked_*/
172 untracked_dir/
173 untracked_repo/
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 &&
181 untracked_*/
182 untracked_dir/
183 untracked_repo/
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_success 'git status --ignored shows same files under dir with or without pathspec' '
199 cat <<-EOF >expect &&
200 ?? an_untracked_dir/
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
209 test_done