3 test_description='git-p4 client view'
7 test_expect_success 'start p4d' '
12 # Construct a client with this list of View lines
29 # Verify these files exist, exactly. Caller creates
30 # a list of files in file "files".
36 test_path_is_file "$arg" &&
40 test_line_count = $num files
44 # Sync up the p4 client, make sure the given files (and only
51 find . -type f ! -name files >files &&
52 check_files_exist "$@"
57 # Make sure the named files, exactly, exist.
62 git ls-files >files &&
63 check_files_exist "$@"
74 test_expect_success 'init depot' '
80 echo dir$d/file$d$f >dir$d/file$d$f &&
81 p4 add dir$d/file$d$f &&
82 p4 submit -d "dir$d/file$d$f"
85 find . -type f ! -name files >files &&
86 check_files_exist dir1/file11 dir1/file12 \
87 dir2/file21 dir2/file22
92 test_expect_success 'unsupported view wildcard %%n' '
93 client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
94 test_when_finished cleanup_git &&
95 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
98 test_expect_success 'unsupported view wildcard *' '
99 client_view "//depot/*/bar/... //client/*/bar/..." &&
100 test_when_finished cleanup_git &&
101 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
104 test_expect_success 'wildcard ... only supported at end of spec 1' '
105 client_view "//depot/.../file11 //client/.../file11" &&
106 test_when_finished cleanup_git &&
107 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
110 test_expect_success 'wildcard ... only supported at end of spec 2' '
111 client_view "//depot/.../a/... //client/.../a/..." &&
112 test_when_finished cleanup_git &&
113 test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
116 test_expect_success 'basic map' '
117 client_view "//depot/dir1/... //client/cli1/..." &&
118 files="cli1/file11 cli1/file12" &&
119 client_verify $files &&
120 test_when_finished cleanup_git &&
121 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
125 test_expect_success 'client view with no mappings' '
128 test_when_finished cleanup_git &&
129 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
133 test_expect_success 'single file map' '
134 client_view "//depot/dir1/file11 //client/file11" &&
136 client_verify $files &&
137 test_when_finished cleanup_git &&
138 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
142 test_expect_success 'later mapping takes precedence (entire repo)' '
143 client_view "//depot/dir1/... //client/cli1/..." \
144 "//depot/... //client/cli2/..." &&
145 files="cli2/dir1/file11 cli2/dir1/file12
146 cli2/dir2/file21 cli2/dir2/file22" &&
147 client_verify $files &&
148 test_when_finished cleanup_git &&
149 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
153 test_expect_success 'later mapping takes precedence (partial repo)' '
154 client_view "//depot/dir1/... //client/..." \
155 "//depot/dir2/... //client/..." &&
156 files="file21 file22" &&
157 client_verify $files &&
158 test_when_finished cleanup_git &&
159 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
163 # Reading the view backwards,
165 # dir1 cannot go to cli12 since it was filled by dir2
166 # dir1 also does not go to cli3, since the second rule
167 # noticed that it matched, but was already filled
168 test_expect_success 'depot path matching rejected client path' '
169 client_view "//depot/dir1/... //client/cli3/..." \
170 "//depot/dir1/... //client/cli12/..." \
171 "//depot/dir2/... //client/cli12/..." &&
172 files="cli12/file21 cli12/file22" &&
173 client_verify $files &&
174 test_when_finished cleanup_git &&
175 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
179 # since both have the same //client/..., the exclusion
180 # rule keeps everything out
181 test_expect_success 'exclusion wildcard, client rhs same (odd)' '
182 client_view "//depot/... //client/..." \
183 "-//depot/dir2/... //client/..." &&
185 test_when_finished cleanup_git &&
186 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
190 test_expect_success 'exclusion wildcard, client rhs different (normal)' '
191 client_view "//depot/... //client/..." \
192 "-//depot/dir2/... //client/dir2/..." &&
193 files="dir1/file11 dir1/file12" &&
194 client_verify $files &&
195 test_when_finished cleanup_git &&
196 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
200 test_expect_success 'exclusion single file' '
201 client_view "//depot/... //client/..." \
202 "-//depot/dir2/file22 //client/file22" &&
203 files="dir1/file11 dir1/file12 dir2/file21" &&
204 client_verify $files &&
205 test_when_finished cleanup_git &&
206 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
210 test_expect_success 'overlay wildcard' '
211 client_view "//depot/dir1/... //client/cli/..." \
212 "+//depot/dir2/... //client/cli/...\n" &&
213 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
214 client_verify $files &&
215 test_when_finished cleanup_git &&
216 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
220 test_expect_success 'overlay single file' '
221 client_view "//depot/dir1/... //client/cli/..." \
222 "+//depot/dir2/file21 //client/cli/file21" &&
223 files="cli/file11 cli/file12 cli/file21" &&
224 client_verify $files &&
225 test_when_finished cleanup_git &&
226 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
230 test_expect_success 'exclusion with later inclusion' '
231 client_view "//depot/... //client/..." \
232 "-//depot/dir2/... //client/dir2/..." \
233 "//depot/dir2/... //client/dir2incl/..." &&
234 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
235 client_verify $files &&
236 test_when_finished cleanup_git &&
237 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
241 test_expect_success 'quotes on rhs only' '
242 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
243 client_verify "cdir 1/file11" "cdir 1/file12" &&
244 test_when_finished cleanup_git &&
245 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
246 git_verify "cdir 1/file11" "cdir 1/file12"
250 # What happens when two files of the same name are overlayed together?
251 # The last-listed file should take preference.
263 test_expect_success 'overlay collision setup' '
264 client_view "//depot/... //client/..." &&
268 echo dir1/filecollide >dir1/filecollide &&
269 p4 add dir1/filecollide &&
270 p4 submit -d dir1/filecollide &&
271 echo dir2/filecollide >dir2/filecollide &&
272 p4 add dir2/filecollide &&
273 p4 submit -d dir2/filecollide
277 test_expect_success 'overlay collision 1 to 2' '
278 client_view "//depot/dir1/... //client/..." \
279 "+//depot/dir2/... //client/..." &&
280 files="file11 file12 file21 file22 filecollide" &&
281 echo dir2/filecollide >actual &&
282 client_verify $files &&
283 test_cmp actual "$cli"/filecollide &&
284 test_when_finished cleanup_git &&
285 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
287 test_cmp actual "$git"/filecollide
290 test_expect_failure 'overlay collision 2 to 1' '
291 client_view "//depot/dir2/... //client/..." \
292 "+//depot/dir1/... //client/..." &&
293 files="file11 file12 file21 file22 filecollide" &&
294 echo dir1/filecollide >actual &&
295 client_verify $files &&
296 test_cmp actual "$cli"/filecollide &&
297 test_when_finished cleanup_git &&
298 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
300 test_cmp actual "$git"/filecollide
303 test_expect_success 'overlay collision delete 2' '
304 client_view "//depot/... //client/..." &&
308 p4 delete dir2/filecollide &&
309 p4 submit -d "remove dir2/filecollide"
313 # no filecollide, got deleted with dir2
314 test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
315 client_view "//depot/dir1/... //client/..." \
316 "+//depot/dir2/... //client/..." &&
317 files="file11 file12 file21 file22" &&
318 client_verify $files &&
319 test_when_finished cleanup_git &&
320 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
324 test_expect_success 'overlay collision update 1' '
325 client_view "//depot/dir1/... //client/dir1/..." &&
329 p4 open dir1/filecollide &&
330 echo dir1/filecollide update >dir1/filecollide &&
331 p4 submit -d "update dir1/filecollide"
335 # still no filecollide, dir2 still wins with the deletion even though the
336 # change to dir1 is more recent
337 test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
338 client_view "//depot/dir1/... //client/..." \
339 "+//depot/dir2/... //client/..." &&
340 files="file11 file12 file21 file22" &&
341 client_verify $files &&
342 test_when_finished cleanup_git &&
343 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
347 test_expect_success 'overlay collision delete filecollides' '
348 client_view "//depot/... //client/..." &&
352 p4 delete dir1/filecollide dir2/filecollide &&
353 p4 submit -d "remove filecollides"
358 # Overlays as part of sync, rather than initial checkout:
359 # 1. add a file in dir1
360 # 2. sync to include it
361 # 3. add same file in dir2
362 # 4. sync, make sure content switches as dir2 has priority
363 # 5. add another file in dir1
365 # 7. add/delete same file in dir2
366 # 8. sync, make sure it disappears, again dir2 wins
381 test_expect_success 'overlay sync: add colA in dir1' '
382 client_view "//depot/dir1/... //client/dir1/..." &&
386 echo dir1/colA >dir1/colA &&
388 p4 submit -d dir1/colA
392 test_expect_success 'overlay sync: initial git checkout' '
393 client_view "//depot/dir1/... //client/..." \
394 "+//depot/dir2/... //client/..." &&
395 files="file11 file12 file21 file22 colA" &&
396 echo dir1/colA >actual &&
397 client_verify $files &&
398 test_cmp actual "$cli"/colA &&
399 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
401 test_cmp actual "$git"/colA
404 test_expect_success 'overlay sync: add colA in dir2' '
405 client_view "//depot/dir2/... //client/dir2/..." &&
409 echo dir2/colA >dir2/colA &&
411 p4 submit -d dir2/colA
415 test_expect_success 'overlay sync: colA content switch' '
416 client_view "//depot/dir1/... //client/..." \
417 "+//depot/dir2/... //client/..." &&
418 files="file11 file12 file21 file22 colA" &&
419 echo dir2/colA >actual &&
420 client_verify $files &&
421 test_cmp actual "$cli"/colA &&
424 "$GITP4" sync --use-client-spec &&
425 git merge --ff-only p4/master
428 test_cmp actual "$git"/colA
431 test_expect_success 'overlay sync: add colB in dir1' '
432 client_view "//depot/dir1/... //client/dir1/..." &&
436 echo dir1/colB >dir1/colB &&
438 p4 submit -d dir1/colB
442 test_expect_success 'overlay sync: colB appears' '
443 client_view "//depot/dir1/... //client/..." \
444 "+//depot/dir2/... //client/..." &&
445 files="file11 file12 file21 file22 colA colB" &&
446 echo dir1/colB >actual &&
447 client_verify $files &&
448 test_cmp actual "$cli"/colB &&
451 "$GITP4" sync --use-client-spec &&
452 git merge --ff-only p4/master
455 test_cmp actual "$git"/colB
458 test_expect_success 'overlay sync: add/delete colB in dir2' '
459 client_view "//depot/dir2/... //client/dir2/..." &&
463 echo dir2/colB >dir2/colB &&
465 p4 submit -d dir2/colB &&
466 p4 delete dir2/colB &&
467 p4 submit -d "delete dir2/colB"
471 test_expect_success 'overlay sync: colB disappears' '
472 client_view "//depot/dir1/... //client/..." \
473 "+//depot/dir2/... //client/..." &&
474 files="file11 file12 file21 file22 colA" &&
475 client_verify $files &&
476 test_when_finished cleanup_git &&
479 "$GITP4" sync --use-client-spec &&
480 git merge --ff-only p4/master
485 test_expect_success 'overlay sync: cleanup' '
486 client_view "//depot/... //client/..." &&
490 p4 delete dir1/colA dir2/colA dir1/colB &&
491 p4 submit -d "remove overlay sync files"
496 # Overlay tests again, but swapped so dir1 has priority.
497 # 1. add a file in dir1
498 # 2. sync to include it
499 # 3. add same file in dir2
500 # 4. sync, make sure content does not switch
501 # 5. add another file in dir1
503 # 7. add/delete same file in dir2
504 # 8. sync, make sure it is still there
519 test_expect_success 'overlay sync swap: add colA in dir1' '
520 client_view "//depot/dir1/... //client/dir1/..." &&
524 echo dir1/colA >dir1/colA &&
526 p4 submit -d dir1/colA
530 test_expect_success 'overlay sync swap: initial git checkout' '
531 client_view "//depot/dir2/... //client/..." \
532 "+//depot/dir1/... //client/..." &&
533 files="file11 file12 file21 file22 colA" &&
534 echo dir1/colA >actual &&
535 client_verify $files &&
536 test_cmp actual "$cli"/colA &&
537 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
539 test_cmp actual "$git"/colA
542 test_expect_success 'overlay sync swap: add colA in dir2' '
543 client_view "//depot/dir2/... //client/dir2/..." &&
547 echo dir2/colA >dir2/colA &&
549 p4 submit -d dir2/colA
553 test_expect_failure 'overlay sync swap: colA no content switch' '
554 client_view "//depot/dir2/... //client/..." \
555 "+//depot/dir1/... //client/..." &&
556 files="file11 file12 file21 file22 colA" &&
557 echo dir1/colA >actual &&
558 client_verify $files &&
559 test_cmp actual "$cli"/colA &&
562 "$GITP4" sync --use-client-spec &&
563 git merge --ff-only p4/master
566 test_cmp actual "$git"/colA
569 test_expect_success 'overlay sync swap: add colB in dir1' '
570 client_view "//depot/dir1/... //client/dir1/..." &&
574 echo dir1/colB >dir1/colB &&
576 p4 submit -d dir1/colB
580 test_expect_success 'overlay sync swap: colB appears' '
581 client_view "//depot/dir2/... //client/..." \
582 "+//depot/dir1/... //client/..." &&
583 files="file11 file12 file21 file22 colA colB" &&
584 echo dir1/colB >actual &&
585 client_verify $files &&
586 test_cmp actual "$cli"/colB &&
589 "$GITP4" sync --use-client-spec &&
590 git merge --ff-only p4/master
593 test_cmp actual "$git"/colB
596 test_expect_success 'overlay sync swap: add/delete colB in dir2' '
597 client_view "//depot/dir2/... //client/dir2/..." &&
601 echo dir2/colB >dir2/colB &&
603 p4 submit -d dir2/colB &&
604 p4 delete dir2/colB &&
605 p4 submit -d "delete dir2/colB"
609 test_expect_failure 'overlay sync swap: colB no change' '
610 client_view "//depot/dir2/... //client/..." \
611 "+//depot/dir1/... //client/..." &&
612 files="file11 file12 file21 file22 colA colB" &&
613 echo dir1/colB >actual &&
614 client_verify $files &&
615 test_cmp actual "$cli"/colB &&
616 test_when_finished cleanup_git &&
619 "$GITP4" sync --use-client-spec &&
620 git merge --ff-only p4/master
623 test_cmp actual "$cli"/colB
626 test_expect_success 'overlay sync swap: cleanup' '
627 client_view "//depot/... //client/..." &&
631 p4 delete dir1/colA dir2/colA dir1/colB &&
632 p4 submit -d "remove overlay sync files"
637 # Rename directories to test quoting in depot-side mappings
646 test_expect_success 'rename files to introduce spaces' '
647 client_view "//depot/... //client/..." &&
648 client_verify dir1/file11 dir1/file12 \
649 dir2/file21 dir2/file22 &&
653 p4 move dir1/... "dir 1"/... &&
655 p4 move dir2/... "dir 2"/... &&
656 p4 submit -d "rename with spaces"
658 client_verify "dir 1/file11" "dir 1/file12" \
659 "dir 2/file21" "dir 2/file22"
662 test_expect_success 'quotes on lhs only' '
663 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
664 files="cdir1/file11 cdir1/file12" &&
665 client_verify $files &&
666 test_when_finished cleanup_git &&
667 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
671 test_expect_success 'quotes on both sides' '
672 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
673 client_verify "cdir 1/file11" "cdir 1/file12" &&
674 test_when_finished cleanup_git &&
675 "$GITP4" clone --use-client-spec --dest="$git" //depot &&
676 git_verify "cdir 1/file11" "cdir 1/file12"
679 test_expect_success 'kill p4d' '