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 "$@"
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"
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' '
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 git p4 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 git p4 clone --use-client-spec --dest="$git" //depot
108 test_expect_success 'wildcard ... only supported at end of spec 1' '
109 client_view "//depot/.../file11 //client/.../file11" &&
110 test_when_finished cleanup_git &&
111 test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
114 test_expect_success 'wildcard ... only supported at end of spec 2' '
115 client_view "//depot/.../a/... //client/.../a/..." &&
116 test_when_finished cleanup_git &&
117 test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
120 test_expect_success 'basic map' '
121 client_view "//depot/dir1/... //client/cli1/..." &&
122 files="cli1/file11 cli1/file12" &&
123 client_verify $files &&
124 test_when_finished cleanup_git &&
125 git p4 clone --use-client-spec --dest="$git" //depot &&
129 test_expect_success 'client view with no mappings' '
132 test_when_finished cleanup_git &&
133 git p4 clone --use-client-spec --dest="$git" //depot &&
137 test_expect_success 'single file map' '
138 client_view "//depot/dir1/file11 //client/file11" &&
140 client_verify $files &&
141 test_when_finished cleanup_git &&
142 git p4 clone --use-client-spec --dest="$git" //depot &&
146 test_expect_success 'later mapping takes precedence (entire repo)' '
147 client_view "//depot/dir1/... //client/cli1/..." \
148 "//depot/... //client/cli2/..." &&
149 files="cli2/dir1/file11 cli2/dir1/file12
150 cli2/dir2/file21 cli2/dir2/file22" &&
151 client_verify $files &&
152 test_when_finished cleanup_git &&
153 git p4 clone --use-client-spec --dest="$git" //depot &&
157 test_expect_success 'later mapping takes precedence (partial repo)' '
158 client_view "//depot/dir1/... //client/..." \
159 "//depot/dir2/... //client/..." &&
160 files="file21 file22" &&
161 client_verify $files &&
162 test_when_finished cleanup_git &&
163 git p4 clone --use-client-spec --dest="$git" //depot &&
167 # Reading the view backwards,
169 # dir1 cannot go to cli12 since it was filled by dir2
170 # dir1 also does not go to cli3, since the second rule
171 # noticed that it matched, but was already filled
172 test_expect_success 'depot path matching rejected client path' '
173 client_view "//depot/dir1/... //client/cli3/..." \
174 "//depot/dir1/... //client/cli12/..." \
175 "//depot/dir2/... //client/cli12/..." &&
176 files="cli12/file21 cli12/file22" &&
177 client_verify $files &&
178 test_when_finished cleanup_git &&
179 git p4 clone --use-client-spec --dest="$git" //depot &&
183 # since both have the same //client/..., the exclusion
184 # rule keeps everything out
185 test_expect_success 'exclusion wildcard, client rhs same (odd)' '
186 client_view "//depot/... //client/..." \
187 "-//depot/dir2/... //client/..." &&
189 test_when_finished cleanup_git &&
190 git p4 clone --use-client-spec --dest="$git" //depot &&
194 test_expect_success 'exclusion wildcard, client rhs different (normal)' '
195 client_view "//depot/... //client/..." \
196 "-//depot/dir2/... //client/dir2/..." &&
197 files="dir1/file11 dir1/file12" &&
198 client_verify $files &&
199 test_when_finished cleanup_git &&
200 git p4 clone --use-client-spec --dest="$git" //depot &&
204 test_expect_success 'exclusion single file' '
205 client_view "//depot/... //client/..." \
206 "-//depot/dir2/file22 //client/file22" &&
207 files="dir1/file11 dir1/file12 dir2/file21" &&
208 client_verify $files &&
209 test_when_finished cleanup_git &&
210 git p4 clone --use-client-spec --dest="$git" //depot &&
214 test_expect_success 'overlay wildcard' '
215 client_view "//depot/dir1/... //client/cli/..." \
216 "+//depot/dir2/... //client/cli/...\n" &&
217 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
218 client_verify $files &&
219 test_when_finished cleanup_git &&
220 git p4 clone --use-client-spec --dest="$git" //depot &&
224 test_expect_success 'overlay single file' '
225 client_view "//depot/dir1/... //client/cli/..." \
226 "+//depot/dir2/file21 //client/cli/file21" &&
227 files="cli/file11 cli/file12 cli/file21" &&
228 client_verify $files &&
229 test_when_finished cleanup_git &&
230 git p4 clone --use-client-spec --dest="$git" //depot &&
234 test_expect_success 'exclusion with later inclusion' '
235 client_view "//depot/... //client/..." \
236 "-//depot/dir2/... //client/dir2/..." \
237 "//depot/dir2/... //client/dir2incl/..." &&
238 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
239 client_verify $files &&
240 test_when_finished cleanup_git &&
241 git p4 clone --use-client-spec --dest="$git" //depot &&
245 test_expect_success 'quotes on rhs only' '
246 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
247 client_verify "cdir 1/file11" "cdir 1/file12" &&
248 test_when_finished cleanup_git &&
249 git p4 clone --use-client-spec --dest="$git" //depot &&
250 git_verify "cdir 1/file11" "cdir 1/file12"
257 # clone sets variable
258 test_expect_success 'clone --use-client-spec sets useClientSpec' '
259 client_view "//depot/... //client/..." &&
260 test_when_finished cleanup_git &&
261 git p4 clone --use-client-spec --dest="$git" //depot &&
264 git config --bool git-p4.useClientSpec >actual &&
270 # clone just a subdir of the client spec
271 test_expect_success 'subdir clone' '
272 client_view "//depot/... //client/..." &&
273 files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
274 client_verify $files &&
275 test_when_finished cleanup_git &&
276 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
277 git_verify dir1/file11 dir1/file12
281 # submit back, see what happens: five cases
283 test_expect_success 'subdir clone, submit modify' '
284 client_view "//depot/... //client/..." &&
285 test_when_finished cleanup_git &&
286 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
289 git config git-p4.skipSubmitEdit true &&
290 echo line >>dir1/file12 &&
291 git add dir1/file12 &&
292 git commit -m dir1/file12 &&
297 test_path_is_file dir1/file12 &&
298 test_line_count = 2 dir1/file12
302 test_expect_success 'subdir clone, submit add' '
303 client_view "//depot/... //client/..." &&
304 test_when_finished cleanup_git &&
305 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
308 git config git-p4.skipSubmitEdit true &&
309 echo file13 >dir1/file13 &&
310 git add dir1/file13 &&
311 git commit -m dir1/file13 &&
316 test_path_is_file dir1/file13
320 test_expect_success 'subdir clone, submit delete' '
321 client_view "//depot/... //client/..." &&
322 test_when_finished cleanup_git &&
323 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
326 git config git-p4.skipSubmitEdit true &&
327 git rm dir1/file12 &&
328 git commit -m "delete dir1/file12" &&
333 test_path_is_missing dir1/file12
337 test_expect_success 'subdir clone, submit copy' '
338 client_view "//depot/... //client/..." &&
339 test_when_finished cleanup_git &&
340 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
343 git config git-p4.skipSubmitEdit true &&
344 git config git-p4.detectCopies true &&
345 cp dir1/file11 dir1/file11a &&
346 git add dir1/file11a &&
347 git commit -m "copy to dir1/file11a" &&
352 test_path_is_file dir1/file11a
356 test_expect_success 'subdir clone, submit rename' '
357 client_view "//depot/... //client/..." &&
358 test_when_finished cleanup_git &&
359 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
362 git config git-p4.skipSubmitEdit true &&
363 git config git-p4.detectRenames true &&
364 git mv dir1/file13 dir1/file13a &&
365 git commit -m "rename dir1/file13 to dir1/file13a" &&
370 test_path_is_missing dir1/file13 &&
371 test_path_is_file dir1/file13a
375 test_expect_success 'reinit depot' '
381 p4 submit -d "delete all files" &&
387 # What happens when two files of the same name are overlayed together?
388 # The last-listed file should take preference.
400 test_expect_success 'overlay collision setup' '
401 client_view "//depot/... //client/..." &&
405 echo dir1/filecollide >dir1/filecollide &&
406 p4 add dir1/filecollide &&
407 p4 submit -d dir1/filecollide &&
408 echo dir2/filecollide >dir2/filecollide &&
409 p4 add dir2/filecollide &&
410 p4 submit -d dir2/filecollide
414 test_expect_success 'overlay collision 1 to 2' '
415 client_view "//depot/dir1/... //client/..." \
416 "+//depot/dir2/... //client/..." &&
417 files="file11 file12 file21 file22 filecollide" &&
418 echo dir2/filecollide >actual &&
419 client_verify $files &&
420 test_cmp actual "$cli"/filecollide &&
421 test_when_finished cleanup_git &&
422 git p4 clone --use-client-spec --dest="$git" //depot &&
424 test_cmp actual "$git"/filecollide
427 test_expect_failure 'overlay collision 2 to 1' '
428 client_view "//depot/dir2/... //client/..." \
429 "+//depot/dir1/... //client/..." &&
430 files="file11 file12 file21 file22 filecollide" &&
431 echo dir1/filecollide >actual &&
432 client_verify $files &&
433 test_cmp actual "$cli"/filecollide &&
434 test_when_finished cleanup_git &&
435 git p4 clone --use-client-spec --dest="$git" //depot &&
437 test_cmp actual "$git"/filecollide
440 test_expect_success 'overlay collision delete 2' '
441 client_view "//depot/... //client/..." &&
445 p4 delete dir2/filecollide &&
446 p4 submit -d "remove dir2/filecollide"
450 # no filecollide, got deleted with dir2
451 test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
452 client_view "//depot/dir1/... //client/..." \
453 "+//depot/dir2/... //client/..." &&
454 files="file11 file12 file21 file22" &&
455 client_verify $files &&
456 test_when_finished cleanup_git &&
457 git p4 clone --use-client-spec --dest="$git" //depot &&
461 test_expect_success 'overlay collision update 1' '
462 client_view "//depot/dir1/... //client/dir1/..." &&
466 p4 open dir1/filecollide &&
467 echo dir1/filecollide update >dir1/filecollide &&
468 p4 submit -d "update dir1/filecollide"
472 # still no filecollide, dir2 still wins with the deletion even though the
473 # change to dir1 is more recent
474 test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
475 client_view "//depot/dir1/... //client/..." \
476 "+//depot/dir2/... //client/..." &&
477 files="file11 file12 file21 file22" &&
478 client_verify $files &&
479 test_when_finished cleanup_git &&
480 git p4 clone --use-client-spec --dest="$git" //depot &&
484 test_expect_success 'overlay collision delete filecollides' '
485 client_view "//depot/... //client/..." &&
489 p4 delete dir1/filecollide dir2/filecollide &&
490 p4 submit -d "remove filecollides"
495 # Overlays as part of sync, rather than initial checkout:
496 # 1. add a file in dir1
497 # 2. sync to include it
498 # 3. add same file in dir2
499 # 4. sync, make sure content switches as dir2 has priority
500 # 5. add another file in dir1
502 # 7. add/delete same file in dir2
503 # 8. sync, make sure it disappears, again dir2 wins
518 test_expect_success 'overlay sync: add colA in dir1' '
519 client_view "//depot/dir1/... //client/dir1/..." &&
523 echo dir1/colA >dir1/colA &&
525 p4 submit -d dir1/colA
529 test_expect_success 'overlay sync: initial git checkout' '
530 client_view "//depot/dir1/... //client/..." \
531 "+//depot/dir2/... //client/..." &&
532 files="file11 file12 file21 file22 colA" &&
533 echo dir1/colA >actual &&
534 client_verify $files &&
535 test_cmp actual "$cli"/colA &&
536 git p4 clone --use-client-spec --dest="$git" //depot &&
538 test_cmp actual "$git"/colA
541 test_expect_success 'overlay sync: add colA in dir2' '
542 client_view "//depot/dir2/... //client/dir2/..." &&
546 echo dir2/colA >dir2/colA &&
548 p4 submit -d dir2/colA
552 test_expect_success 'overlay sync: colA content switch' '
553 client_view "//depot/dir1/... //client/..." \
554 "+//depot/dir2/... //client/..." &&
555 files="file11 file12 file21 file22 colA" &&
556 echo dir2/colA >actual &&
557 client_verify $files &&
558 test_cmp actual "$cli"/colA &&
561 git p4 sync --use-client-spec &&
562 git merge --ff-only p4/master
565 test_cmp actual "$git"/colA
568 test_expect_success 'overlay sync: add colB in dir1' '
569 client_view "//depot/dir1/... //client/dir1/..." &&
573 echo dir1/colB >dir1/colB &&
575 p4 submit -d dir1/colB
579 test_expect_success 'overlay sync: colB appears' '
580 client_view "//depot/dir1/... //client/..." \
581 "+//depot/dir2/... //client/..." &&
582 files="file11 file12 file21 file22 colA colB" &&
583 echo dir1/colB >actual &&
584 client_verify $files &&
585 test_cmp actual "$cli"/colB &&
588 git p4 sync --use-client-spec &&
589 git merge --ff-only p4/master
592 test_cmp actual "$git"/colB
595 test_expect_success 'overlay sync: add/delete colB in dir2' '
596 client_view "//depot/dir2/... //client/dir2/..." &&
600 echo dir2/colB >dir2/colB &&
602 p4 submit -d dir2/colB &&
603 p4 delete dir2/colB &&
604 p4 submit -d "delete dir2/colB"
608 test_expect_success 'overlay sync: colB disappears' '
609 client_view "//depot/dir1/... //client/..." \
610 "+//depot/dir2/... //client/..." &&
611 files="file11 file12 file21 file22 colA" &&
612 client_verify $files &&
613 test_when_finished cleanup_git &&
616 git p4 sync --use-client-spec &&
617 git merge --ff-only p4/master
622 test_expect_success 'overlay sync: cleanup' '
623 client_view "//depot/... //client/..." &&
627 p4 delete dir1/colA dir2/colA dir1/colB &&
628 p4 submit -d "remove overlay sync files"
633 # Overlay tests again, but swapped so dir1 has priority.
634 # 1. add a file in dir1
635 # 2. sync to include it
636 # 3. add same file in dir2
637 # 4. sync, make sure content does not switch
638 # 5. add another file in dir1
640 # 7. add/delete same file in dir2
641 # 8. sync, make sure it is still there
656 test_expect_success 'overlay sync swap: add colA in dir1' '
657 client_view "//depot/dir1/... //client/dir1/..." &&
661 echo dir1/colA >dir1/colA &&
663 p4 submit -d dir1/colA
667 test_expect_success 'overlay sync swap: initial git checkout' '
668 client_view "//depot/dir2/... //client/..." \
669 "+//depot/dir1/... //client/..." &&
670 files="file11 file12 file21 file22 colA" &&
671 echo dir1/colA >actual &&
672 client_verify $files &&
673 test_cmp actual "$cli"/colA &&
674 git p4 clone --use-client-spec --dest="$git" //depot &&
676 test_cmp actual "$git"/colA
679 test_expect_success 'overlay sync swap: add colA in dir2' '
680 client_view "//depot/dir2/... //client/dir2/..." &&
684 echo dir2/colA >dir2/colA &&
686 p4 submit -d dir2/colA
690 test_expect_failure 'overlay sync swap: colA no content switch' '
691 client_view "//depot/dir2/... //client/..." \
692 "+//depot/dir1/... //client/..." &&
693 files="file11 file12 file21 file22 colA" &&
694 echo dir1/colA >actual &&
695 client_verify $files &&
696 test_cmp actual "$cli"/colA &&
699 git p4 sync --use-client-spec &&
700 git merge --ff-only p4/master
703 test_cmp actual "$git"/colA
706 test_expect_success 'overlay sync swap: add colB in dir1' '
707 client_view "//depot/dir1/... //client/dir1/..." &&
711 echo dir1/colB >dir1/colB &&
713 p4 submit -d dir1/colB
717 test_expect_success 'overlay sync swap: colB appears' '
718 client_view "//depot/dir2/... //client/..." \
719 "+//depot/dir1/... //client/..." &&
720 files="file11 file12 file21 file22 colA colB" &&
721 echo dir1/colB >actual &&
722 client_verify $files &&
723 test_cmp actual "$cli"/colB &&
726 git p4 sync --use-client-spec &&
727 git merge --ff-only p4/master
730 test_cmp actual "$git"/colB
733 test_expect_success 'overlay sync swap: add/delete colB in dir2' '
734 client_view "//depot/dir2/... //client/dir2/..." &&
738 echo dir2/colB >dir2/colB &&
740 p4 submit -d dir2/colB &&
741 p4 delete dir2/colB &&
742 p4 submit -d "delete dir2/colB"
746 test_expect_failure 'overlay sync swap: colB no change' '
747 client_view "//depot/dir2/... //client/..." \
748 "+//depot/dir1/... //client/..." &&
749 files="file11 file12 file21 file22 colA colB" &&
750 echo dir1/colB >actual &&
751 client_verify $files &&
752 test_cmp actual "$cli"/colB &&
753 test_when_finished cleanup_git &&
756 git p4 sync --use-client-spec &&
757 git merge --ff-only p4/master
760 test_cmp actual "$cli"/colB
763 test_expect_success 'overlay sync swap: cleanup' '
764 client_view "//depot/... //client/..." &&
768 p4 delete dir1/colA dir2/colA dir1/colB &&
769 p4 submit -d "remove overlay sync files"
774 # Rename directories to test quoting in depot-side mappings
783 test_expect_success 'rename files to introduce spaces' '
784 client_view "//depot/... //client/..." &&
785 client_verify dir1/file11 dir1/file12 \
786 dir2/file21 dir2/file22 &&
790 p4 move dir1/... "dir 1"/... &&
792 p4 move dir2/... "dir 2"/... &&
793 p4 submit -d "rename with spaces"
795 client_verify "dir 1/file11" "dir 1/file12" \
796 "dir 2/file21" "dir 2/file22"
799 test_expect_success 'quotes on lhs only' '
800 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
801 files="cdir1/file11 cdir1/file12" &&
802 client_verify $files &&
803 test_when_finished cleanup_git &&
804 git p4 clone --use-client-spec --dest="$git" //depot &&
808 test_expect_success 'quotes on both sides' '
809 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
810 client_verify "cdir 1/file11" "cdir 1/file12" &&
811 test_when_finished cleanup_git &&
812 git p4 clone --use-client-spec --dest="$git" //depot &&
813 git_verify "cdir 1/file11" "cdir 1/file12"
816 test_expect_success 'kill p4d' '