ident.c: add split_ident_line() to parse formatted ident line
[git.git] / t / t9809-git-p4-client-view.sh
blobb0c6d4391daa041cf379f402704fb0989849e727
1 #!/bin/sh
3 test_description='git-p4 client view'
5 . ./lib-git-p4.sh
7 test_expect_success 'start p4d' '
8 start_p4d
12 # Construct a client with this list of View lines
14 client_view() {
16 cat <<-EOF &&
17 Client: client
18 Description: client
19 Root: $cli
20 View:
21 EOF
22 for arg ; do
23 printf "\t$arg\n"
24 done
25 ) | p4 client -i
29 # Verify these files exist, exactly. Caller creates
30 # a list of files in file "files".
32 check_files_exist() {
33 ok=0 &&
34 num=$# &&
35 for arg ; do
36 test_path_is_file "$arg" &&
37 ok=$(($ok + 1))
38 done &&
39 test $ok -eq $num &&
40 test_line_count = $num files
44 # Sync up the p4 client, make sure the given files (and only
45 # those) exist.
47 client_verify() {
49 cd "$cli" &&
50 p4 sync &&
51 find . -type f ! -name files >files &&
52 check_files_exist "$@"
57 # Make sure the named files, exactly, exist.
59 git_verify() {
61 cd "$git" &&
62 git ls-files >files &&
63 check_files_exist "$@"
67 # //depot
68 # - dir1
69 # - file11
70 # - file12
71 # - dir2
72 # - file21
73 # - file22
74 init_depot() {
75 for d in 1 2 ; do
76 mkdir -p dir$d &&
77 for f in 1 2 ; do
78 echo dir$d/file$d$f >dir$d/file$d$f &&
79 p4 add dir$d/file$d$f &&
80 p4 submit -d "dir$d/file$d$f"
81 done
82 done &&
83 find . -type f ! -name files >files &&
84 check_files_exist dir1/file11 dir1/file12 \
85 dir2/file21 dir2/file22
88 test_expect_success 'init depot' '
90 cd "$cli" &&
91 init_depot
95 # double % for printf
96 test_expect_success 'unsupported view wildcard %%n' '
97 client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
98 test_when_finished cleanup_git &&
99 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
102 test_expect_success 'unsupported view wildcard *' '
103 client_view "//depot/*/bar/... //client/*/bar/..." &&
104 test_when_finished cleanup_git &&
105 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
108 test_expect_success 'wildcard ... only supported at end of spec' '
109 client_view "//depot/.../file11 //client/.../file11" &&
110 test_when_finished cleanup_git &&
111 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
114 test_expect_success 'basic map' '
115 client_view "//depot/dir1/... //client/cli1/..." &&
116 files="cli1/file11 cli1/file12" &&
117 client_verify $files &&
118 test_when_finished cleanup_git &&
119 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
120 git_verify $files
123 test_expect_success 'client view with no mappings' '
124 client_view &&
125 client_verify &&
126 test_when_finished cleanup_git &&
127 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
128 git_verify
131 test_expect_success 'single file map' '
132 client_view "//depot/dir1/file11 //client/file11" &&
133 files="file11" &&
134 client_verify $files &&
135 test_when_finished cleanup_git &&
136 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
137 git_verify $files
140 test_expect_success 'later mapping takes precedence (entire repo)' '
141 client_view "//depot/dir1/... //client/cli1/..." \
142 "//depot/... //client/cli2/..." &&
143 files="cli2/dir1/file11 cli2/dir1/file12
144 cli2/dir2/file21 cli2/dir2/file22" &&
145 client_verify $files &&
146 test_when_finished cleanup_git &&
147 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
148 git_verify $files
151 test_expect_success 'later mapping takes precedence (partial repo)' '
152 client_view "//depot/dir1/... //client/..." \
153 "//depot/dir2/... //client/..." &&
154 files="file21 file22" &&
155 client_verify $files &&
156 test_when_finished cleanup_git &&
157 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
158 git_verify $files
161 # Reading the view backwards,
162 # dir2 goes to cli12
163 # dir1 cannot go to cli12 since it was filled by dir2
164 # dir1 also does not go to cli3, since the second rule
165 # noticed that it matched, but was already filled
166 test_expect_success 'depot path matching rejected client path' '
167 client_view "//depot/dir1/... //client/cli3/..." \
168 "//depot/dir1/... //client/cli12/..." \
169 "//depot/dir2/... //client/cli12/..." &&
170 files="cli12/file21 cli12/file22" &&
171 client_verify $files &&
172 test_when_finished cleanup_git &&
173 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
174 git_verify $files
177 # since both have the same //client/..., the exclusion
178 # rule keeps everything out
179 test_expect_success 'exclusion wildcard, client rhs same (odd)' '
180 client_view "//depot/... //client/..." \
181 "-//depot/dir2/... //client/..." &&
182 client_verify &&
183 test_when_finished cleanup_git &&
184 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
185 git_verify
188 test_expect_success 'exclusion wildcard, client rhs different (normal)' '
189 client_view "//depot/... //client/..." \
190 "-//depot/dir2/... //client/dir2/..." &&
191 files="dir1/file11 dir1/file12" &&
192 client_verify $files &&
193 test_when_finished cleanup_git &&
194 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
195 git_verify $files
198 test_expect_success 'exclusion single file' '
199 client_view "//depot/... //client/..." \
200 "-//depot/dir2/file22 //client/file22" &&
201 files="dir1/file11 dir1/file12 dir2/file21" &&
202 client_verify $files &&
203 test_when_finished cleanup_git &&
204 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
205 git_verify $files
208 test_expect_success 'overlay wildcard' '
209 client_view "//depot/dir1/... //client/cli/..." \
210 "+//depot/dir2/... //client/cli/...\n" &&
211 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
212 client_verify $files &&
213 test_when_finished cleanup_git &&
214 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
215 git_verify $files
218 test_expect_success 'overlay single file' '
219 client_view "//depot/dir1/... //client/cli/..." \
220 "+//depot/dir2/file21 //client/cli/file21" &&
221 files="cli/file11 cli/file12 cli/file21" &&
222 client_verify $files &&
223 test_when_finished cleanup_git &&
224 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
225 git_verify $files
228 test_expect_success 'exclusion with later inclusion' '
229 client_view "//depot/... //client/..." \
230 "-//depot/dir2/... //client/dir2/..." \
231 "//depot/dir2/... //client/dir2incl/..." &&
232 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
233 client_verify $files &&
234 test_when_finished cleanup_git &&
235 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
236 git_verify $files
239 test_expect_success 'quotes on rhs only' '
240 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
241 client_verify "cdir 1/file11" "cdir 1/file12" &&
242 test_when_finished cleanup_git &&
243 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
244 git_verify "cdir 1/file11" "cdir 1/file12"
248 # Submit tests
251 # clone sets variable
252 test_expect_success 'clone --use-client-spec sets useClientSpec' '
253 client_view "//depot/... //client/..." &&
254 test_when_finished cleanup_git &&
255 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
257 cd "$git" &&
258 git config --bool git-p4.useClientSpec >actual &&
259 echo true >true &&
260 test_cmp actual true
264 # clone just a subdir of the client spec
265 test_expect_success 'subdir clone' '
266 client_view "//depot/... //client/..." &&
267 files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
268 client_verify $files &&
269 test_when_finished cleanup_git &&
270 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
271 git_verify dir1/file11 dir1/file12
275 # submit back, see what happens: five cases
277 test_expect_success 'subdir clone, submit modify' '
278 client_view "//depot/... //client/..." &&
279 test_when_finished cleanup_git &&
280 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
282 cd "$git" &&
283 git config git-p4.skipSubmitEdit true &&
284 echo line >>dir1/file12 &&
285 git add dir1/file12 &&
286 git commit -m dir1/file12 &&
287 "$GITP4" submit
288 ) &&
290 cd "$cli" &&
291 test_path_is_file dir1/file12 &&
292 test_line_count = 2 dir1/file12
296 test_expect_success 'subdir clone, submit add' '
297 client_view "//depot/... //client/..." &&
298 test_when_finished cleanup_git &&
299 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
301 cd "$git" &&
302 git config git-p4.skipSubmitEdit true &&
303 echo file13 >dir1/file13 &&
304 git add dir1/file13 &&
305 git commit -m dir1/file13 &&
306 "$GITP4" submit
307 ) &&
309 cd "$cli" &&
310 test_path_is_file dir1/file13
314 test_expect_success 'subdir clone, submit delete' '
315 client_view "//depot/... //client/..." &&
316 test_when_finished cleanup_git &&
317 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
319 cd "$git" &&
320 git config git-p4.skipSubmitEdit true &&
321 git rm dir1/file12 &&
322 git commit -m "delete dir1/file12" &&
323 "$GITP4" submit
324 ) &&
326 cd "$cli" &&
327 test_path_is_missing dir1/file12
331 test_expect_success 'subdir clone, submit copy' '
332 client_view "//depot/... //client/..." &&
333 test_when_finished cleanup_git &&
334 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
336 cd "$git" &&
337 git config git-p4.skipSubmitEdit true &&
338 git config git-p4.detectCopies true &&
339 cp dir1/file11 dir1/file11a &&
340 git add dir1/file11a &&
341 git commit -m "copy to dir1/file11a" &&
342 "$GITP4" submit
343 ) &&
345 cd "$cli" &&
346 test_path_is_file dir1/file11a
350 test_expect_success 'subdir clone, submit rename' '
351 client_view "//depot/... //client/..." &&
352 test_when_finished cleanup_git &&
353 "$GITP4" clone --use-client-spec --dest="$git" //depot/dir1 &&
355 cd "$git" &&
356 git config git-p4.skipSubmitEdit true &&
357 git config git-p4.detectRenames true &&
358 git mv dir1/file13 dir1/file13a &&
359 git commit -m "rename dir1/file13 to dir1/file13a" &&
360 "$GITP4" submit
361 ) &&
363 cd "$cli" &&
364 test_path_is_missing dir1/file13 &&
365 test_path_is_file dir1/file13a
369 test_expect_success 'reinit depot' '
371 cd "$cli" &&
372 p4 sync -f &&
373 rm files &&
374 p4 delete */* &&
375 p4 submit -d "delete all files" &&
376 init_depot
381 # Rename directories to test quoting in depot-side mappings
382 # //depot
383 # - "dir 1"
384 # - file11
385 # - file12
386 # - "dir 2"
387 # - file21
388 # - file22
390 test_expect_success 'rename files to introduce spaces' '
391 client_view "//depot/... //client/..." &&
392 client_verify dir1/file11 dir1/file12 \
393 dir2/file21 dir2/file22 &&
395 cd "$cli" &&
396 p4 open dir1/... &&
397 p4 move dir1/... "dir 1"/... &&
398 p4 open dir2/... &&
399 p4 move dir2/... "dir 2"/... &&
400 p4 submit -d "rename with spaces"
401 ) &&
402 client_verify "dir 1/file11" "dir 1/file12" \
403 "dir 2/file21" "dir 2/file22"
406 test_expect_success 'quotes on lhs only' '
407 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
408 files="cdir1/file11 cdir1/file12" &&
409 client_verify $files &&
410 test_when_finished cleanup_git &&
411 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
412 client_verify $files
415 test_expect_success 'quotes on both sides' '
416 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
417 client_verify "cdir 1/file11" "cdir 1/file12" &&
418 test_when_finished cleanup_git &&
419 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
420 git_verify "cdir 1/file11" "cdir 1/file12"
423 test_expect_success 'kill p4d' '
424 kill_p4d
427 test_done