summaryrefslogtreecommitdiff
path: root/t/t3011-common-prefixes-and-directory-traversal.sh
blob: 3da5b2b6e795ec4587608ead8bc10abf0c6d9039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh

test_description='directory traversal handling, especially with common prefixes'

. ./test-lib.sh

test_expect_success 'setup' '
	test_commit hello &&

	>empty &&
	mkdir untracked_dir &&
	>untracked_dir/empty &&
	git init untracked_repo &&
	>untracked_repo/empty &&

	cat <<-EOF >.gitignore &&
	ignored
	an_ignored_dir/
	EOF
	mkdir an_ignored_dir &&
	mkdir an_untracked_dir &&
	>an_ignored_dir/ignored &&
	>an_ignored_dir/untracked &&
	>an_untracked_dir/ignored &&
	>an_untracked_dir/untracked
'

test_expect_success 'git ls-files -o shows the right entries' '
	cat <<-EOF >expect &&
	.gitignore
	actual
	an_ignored_dir/ignored
	an_ignored_dir/untracked
	an_untracked_dir/ignored
	an_untracked_dir/untracked
	empty
	expect
	untracked_dir/empty
	untracked_repo/
	EOF
	git ls-files -o >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o --exclude-standard shows the right entries' '
	cat <<-EOF >expect &&
	.gitignore
	actual
	an_untracked_dir/untracked
	empty
	expect
	untracked_dir/empty
	untracked_repo/
	EOF
	git ls-files -o --exclude-standard >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o untracked_dir recurses' '
	echo untracked_dir/empty >expect &&
	git ls-files -o untracked_dir >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o untracked_dir/ recurses' '
	echo untracked_dir/empty >expect &&
	git ls-files -o untracked_dir/ >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o --directory untracked_dir does not recurse' '
	echo untracked_dir/ >expect &&
	git ls-files -o --directory untracked_dir >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o --directory untracked_dir/ does not recurse' '
	echo untracked_dir/ >expect &&
	git ls-files -o --directory untracked_dir/ >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o untracked_repo does not recurse' '
	echo untracked_repo/ >expect &&
	git ls-files -o untracked_repo >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o untracked_repo/ does not recurse' '
	echo untracked_repo/ >expect &&
	git ls-files -o untracked_repo/ >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o untracked_dir untracked_repo recurses into untracked_dir only' '
	cat <<-EOF >expect &&
	untracked_dir/empty
	untracked_repo/
	EOF
	git ls-files -o untracked_dir untracked_repo >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o untracked_dir/ untracked_repo/ recurses into untracked_dir only' '
	cat <<-EOF >expect &&
	untracked_dir/empty
	untracked_repo/
	EOF
	git ls-files -o untracked_dir/ untracked_repo/ >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o --directory untracked_dir untracked_repo does not recurse' '
	cat <<-EOF >expect &&
	untracked_dir/
	untracked_repo/
	EOF
	git ls-files -o --directory untracked_dir untracked_repo >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o --directory untracked_dir/ untracked_repo/ does not recurse' '
	cat <<-EOF >expect &&
	untracked_dir/
	untracked_repo/
	EOF
	git ls-files -o --directory untracked_dir/ untracked_repo/ >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o .git shows nothing' '
	git ls-files -o .git >actual &&
	test_must_be_empty actual
'

test_expect_success 'git ls-files -o .git/ shows nothing' '
	git ls-files -o .git/ >actual &&
	test_must_be_empty actual
'

test_expect_success FUNNYNAMES 'git ls-files -o untracked_* recurses appropriately' '
	mkdir "untracked_*" &&
	>"untracked_*/empty" &&

	cat <<-EOF >expect &&
	untracked_*/empty
	untracked_dir/empty
	untracked_repo/
	EOF
	git ls-files -o "untracked_*" >actual &&
	test_cmp expect actual
'

# It turns out fill_directory returns the right paths, but ls-files' post-call
# filtering in show_dir_entry() via calling dir_path_match() which ends up
# in git_fnmatch() has logic for PATHSPEC_ONESTAR that assumes the pathspec
# must match the full path; it doesn't check it for matching a leading
# directory.
test_expect_failure FUNNYNAMES 'git ls-files -o untracked_*/ recurses appropriately' '
	cat <<-EOF >expect &&
	untracked_*/empty
	untracked_dir/empty
	untracked_repo/
	EOF
	git ls-files -o "untracked_*/" >actual &&
	test_cmp expect actual
'

test_expect_success FUNNYNAMES 'git ls-files -o --directory untracked_* does not recurse' '
	cat <<-EOF >expect &&
	untracked_*/
	untracked_dir/
	untracked_repo/
	EOF
	git ls-files -o --directory "untracked_*" >actual &&
	test_cmp expect actual
'

test_expect_success FUNNYNAMES 'git ls-files -o --directory untracked_*/ does not recurse' '
	cat <<-EOF >expect &&
	untracked_*/
	untracked_dir/
	untracked_repo/
	EOF
	git ls-files -o --directory "untracked_*/" >actual &&
	test_cmp expect actual
'

test_expect_success 'git ls-files -o consistent between one or two dirs' '
	git ls-files -o --exclude-standard an_ignored_dir/ an_untracked_dir/ >tmp &&
	! grep ^an_ignored_dir/ tmp >expect &&
	git ls-files -o --exclude-standard an_ignored_dir/ >actual &&
	test_cmp expect actual
'

# ls-files doesn't have a way to request showing both untracked and ignored
# files at the same time, so use `git status --ignored`
test_expect_success 'git status --ignored shows same files under dir with or without pathspec' '
	cat <<-EOF >expect &&
	?? an_untracked_dir/
	!! an_untracked_dir/ignored
	EOF
	git status --porcelain --ignored >output &&
	grep an_untracked_dir output >expect &&
	git status --porcelain --ignored an_untracked_dir/ >actual &&
	test_cmp expect actual
'

test_done