3 test_description='git p4 client view'
7 test_expect_success 'start p4d' '
12 # Verify these files exist, exactly. Caller creates
13 # a list of files in file "files".
19 test_path_is_file "$arg" &&
23 test_line_count = $num files
27 # Sync up the p4 client, make sure the given files (and only
34 find . -type f ! -name files >files &&
35 check_files_exist "$@"
40 # Make sure the named files, exactly, exist.
45 git ls-files >files &&
46 check_files_exist "$@"
61 echo dir$d/file$d$f >dir$d/file$d$f &&
62 p4 add dir$d/file$d$f &&
63 p4 submit -d "dir$d/file$d$f"
66 find . -type f ! -name files >files &&
67 check_files_exist dir1/file11 dir1/file12 \
68 dir2/file21 dir2/file22
71 test_expect_success 'init depot' '
79 test_expect_success 'view wildcard %%n' '
80 client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
81 test_when_finished cleanup_git &&
82 git p4 clone --use-client-spec --dest="$git" //depot
85 test_expect_success 'view wildcard *' '
86 client_view "//depot/*/bar/... //client/*/bar/..." &&
87 test_when_finished cleanup_git &&
88 git p4 clone --use-client-spec --dest="$git" //depot
91 test_expect_success 'wildcard ... in the middle' '
92 client_view "//depot/.../file11 //client/.../file11" &&
93 test_when_finished cleanup_git &&
94 git p4 clone --use-client-spec --dest="$git" //depot
97 test_expect_success 'wildcard ... in the middle and at the end' '
98 client_view "//depot/.../a/... //client/.../a/..." &&
99 test_when_finished cleanup_git &&
100 git p4 clone --use-client-spec --dest="$git" //depot
103 test_expect_success 'basic map' '
104 client_view "//depot/dir1/... //client/cli1/..." &&
105 files="cli1/file11 cli1/file12" &&
106 client_verify $files &&
107 test_when_finished cleanup_git &&
108 git p4 clone --use-client-spec --dest="$git" //depot &&
112 test_expect_success 'client view with no mappings' '
115 test_when_finished cleanup_git &&
116 git p4 clone --use-client-spec --dest="$git" //depot &&
120 test_expect_success 'single file map' '
121 client_view "//depot/dir1/file11 //client/file11" &&
123 client_verify $files &&
124 test_when_finished cleanup_git &&
125 git p4 clone --use-client-spec --dest="$git" //depot &&
129 test_expect_success 'later mapping takes precedence (entire repo)' '
130 client_view "//depot/dir1/... //client/cli1/..." \
131 "//depot/... //client/cli2/..." &&
132 files="cli2/dir1/file11 cli2/dir1/file12
133 cli2/dir2/file21 cli2/dir2/file22" &&
134 client_verify $files &&
135 test_when_finished cleanup_git &&
136 git p4 clone --use-client-spec --dest="$git" //depot &&
140 test_expect_success 'later mapping takes precedence (partial repo)' '
141 client_view "//depot/dir1/... //client/..." \
142 "//depot/dir2/... //client/..." &&
143 files="file21 file22" &&
144 client_verify $files &&
145 test_when_finished cleanup_git &&
146 git p4 clone --use-client-spec --dest="$git" //depot &&
150 # Reading the view backwards,
152 # dir1 cannot go to cli12 since it was filled by dir2
153 # dir1 also does not go to cli3, since the second rule
154 # noticed that it matched, but was already filled
155 test_expect_success 'depot path matching rejected client path' '
156 client_view "//depot/dir1/... //client/cli3/..." \
157 "//depot/dir1/... //client/cli12/..." \
158 "//depot/dir2/... //client/cli12/..." &&
159 files="cli12/file21 cli12/file22" &&
160 client_verify $files &&
161 test_when_finished cleanup_git &&
162 git p4 clone --use-client-spec --dest="$git" //depot &&
166 # since both have the same //client/..., the exclusion
167 # rule keeps everything out
168 test_expect_success 'exclusion wildcard, client rhs same (odd)' '
169 client_view "//depot/... //client/..." \
170 "-//depot/dir2/... //client/..." &&
172 test_when_finished cleanup_git &&
173 git p4 clone --use-client-spec --dest="$git" //depot &&
177 test_expect_success 'exclusion wildcard, client rhs different (normal)' '
178 client_view "//depot/... //client/..." \
179 "-//depot/dir2/... //client/dir2/..." &&
180 files="dir1/file11 dir1/file12" &&
181 client_verify $files &&
182 test_when_finished cleanup_git &&
183 git p4 clone --use-client-spec --dest="$git" //depot &&
187 test_expect_success 'exclusion single file' '
188 client_view "//depot/... //client/..." \
189 "-//depot/dir2/file22 //client/file22" &&
190 files="dir1/file11 dir1/file12 dir2/file21" &&
191 client_verify $files &&
192 test_when_finished cleanup_git &&
193 git p4 clone --use-client-spec --dest="$git" //depot &&
197 test_expect_success 'overlay wildcard' '
198 client_view "//depot/dir1/... //client/cli/..." \
199 "+//depot/dir2/... //client/cli/..." &&
200 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
201 client_verify $files &&
202 test_when_finished cleanup_git &&
203 git p4 clone --use-client-spec --dest="$git" //depot &&
207 test_expect_success 'overlay single file' '
208 client_view "//depot/dir1/... //client/cli/..." \
209 "+//depot/dir2/file21 //client/cli/file21" &&
210 files="cli/file11 cli/file12 cli/file21" &&
211 client_verify $files &&
212 test_when_finished cleanup_git &&
213 git p4 clone --use-client-spec --dest="$git" //depot &&
217 test_expect_success 'exclusion with later inclusion' '
218 client_view "//depot/... //client/..." \
219 "-//depot/dir2/... //client/dir2/..." \
220 "//depot/dir2/... //client/dir2incl/..." &&
221 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
222 client_verify $files &&
223 test_when_finished cleanup_git &&
224 git p4 clone --use-client-spec --dest="$git" //depot &&
228 test_expect_success 'quotes on rhs only' '
229 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
230 client_verify "cdir 1/file11" "cdir 1/file12" &&
231 test_when_finished cleanup_git &&
232 git p4 clone --use-client-spec --dest="$git" //depot &&
233 git_verify "cdir 1/file11" "cdir 1/file12"
240 # clone sets variable
241 test_expect_success 'clone --use-client-spec sets useClientSpec' '
242 client_view "//depot/... //client/..." &&
243 test_when_finished cleanup_git &&
244 git p4 clone --use-client-spec --dest="$git" //depot &&
247 git config --bool git-p4.useClientSpec >actual &&
253 # clone just a subdir of the client spec
254 test_expect_success 'subdir clone' '
255 client_view "//depot/... //client/..." &&
256 files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
257 client_verify $files &&
258 test_when_finished cleanup_git &&
259 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
260 git_verify dir1/file11 dir1/file12
264 # submit back, see what happens: five cases
266 test_expect_success 'subdir clone, submit modify' '
267 client_view "//depot/... //client/..." &&
268 test_when_finished cleanup_git &&
269 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
272 git config git-p4.skipSubmitEdit true &&
273 echo line >>dir1/file12 &&
274 git add dir1/file12 &&
275 git commit -m dir1/file12 &&
280 test_path_is_file dir1/file12 &&
281 test_line_count = 2 dir1/file12
285 test_expect_success 'subdir clone, submit add' '
286 client_view "//depot/... //client/..." &&
287 test_when_finished cleanup_git &&
288 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
291 git config git-p4.skipSubmitEdit true &&
292 echo file13 >dir1/file13 &&
293 git add dir1/file13 &&
294 git commit -m dir1/file13 &&
299 test_path_is_file dir1/file13
303 test_expect_success 'subdir clone, submit delete' '
304 client_view "//depot/... //client/..." &&
305 test_when_finished cleanup_git &&
306 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
309 git config git-p4.skipSubmitEdit true &&
310 git rm dir1/file12 &&
311 git commit -m "delete dir1/file12" &&
316 test_path_is_missing dir1/file12
320 test_expect_success 'subdir clone, submit copy' '
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 config git-p4.detectCopies true &&
328 cp dir1/file11 dir1/file11a &&
329 git add dir1/file11a &&
330 git commit -m "copy to dir1/file11a" &&
335 test_path_is_file dir1/file11a &&
336 ! is_cli_file_writeable dir1/file11a
340 test_expect_success 'subdir clone, submit rename' '
341 client_view "//depot/... //client/..." &&
342 test_when_finished cleanup_git &&
343 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
346 git config git-p4.skipSubmitEdit true &&
347 git config git-p4.detectRenames true &&
348 git mv dir1/file13 dir1/file13a &&
349 git commit -m "rename dir1/file13 to dir1/file13a" &&
354 test_path_is_missing dir1/file13 &&
355 test_path_is_file dir1/file13a &&
356 ! is_cli_file_writeable dir1/file13a
360 # see t9800 for the non-client-spec case, and the rest of the wildcard tests
361 test_expect_success 'wildcard files submit back to p4, client-spec case' '
362 client_view "//depot/... //client/..." &&
363 test_when_finished cleanup_git &&
364 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
367 echo git-wild-hash >dir1/git-wild#hash &&
368 if test_have_prereq NOT_MINGW NOT_CYGWIN
370 echo git-wild-star >dir1/git-wild\*star
372 echo git-wild-at >dir1/git-wild@at &&
373 echo git-wild-percent >dir1/git-wild%percent &&
374 git add dir1/git-wild* &&
375 git commit -m "add some wildcard filenames" &&
376 git config git-p4.skipSubmitEditCheck true &&
381 test_path_is_file dir1/git-wild#hash &&
382 if test_have_prereq NOT_MINGW NOT_CYGWIN
384 test_path_is_file dir1/git-wild\*star
386 test_path_is_file dir1/git-wild@at &&
387 test_path_is_file dir1/git-wild%percent
390 # delete these carefully, cannot just do "p4 delete"
391 # on files with wildcards; but git-p4 knows how
393 git rm dir1/git-wild* &&
394 git commit -m "clean up the wildcards" &&
399 test_expect_success 'reinit depot' '
404 p4 submit -d "delete all files" &&
410 # What happens when two files of the same name are overlayed together?
411 # The last-listed file should take preference.
423 test_expect_success 'overlay collision setup' '
424 client_view "//depot/... //client/..." &&
428 echo dir1/filecollide >dir1/filecollide &&
429 p4 add dir1/filecollide &&
430 p4 submit -d dir1/filecollide &&
431 echo dir2/filecollide >dir2/filecollide &&
432 p4 add dir2/filecollide &&
433 p4 submit -d dir2/filecollide
437 test_expect_success 'overlay collision 1 to 2' '
438 client_view "//depot/dir1/... //client/..." \
439 "+//depot/dir2/... //client/..." &&
440 files="file11 file12 file21 file22 filecollide" &&
441 echo dir2/filecollide >actual &&
442 client_verify $files &&
443 test_cmp actual "$cli"/filecollide &&
444 test_when_finished cleanup_git &&
445 git p4 clone --use-client-spec --dest="$git" //depot &&
447 test_cmp actual "$git"/filecollide
450 test_expect_failure 'overlay collision 2 to 1' '
451 client_view "//depot/dir2/... //client/..." \
452 "+//depot/dir1/... //client/..." &&
453 files="file11 file12 file21 file22 filecollide" &&
454 echo dir1/filecollide >actual &&
455 client_verify $files &&
456 test_cmp actual "$cli"/filecollide &&
457 test_when_finished cleanup_git &&
458 git p4 clone --use-client-spec --dest="$git" //depot &&
460 test_cmp actual "$git"/filecollide
463 test_expect_success 'overlay collision delete 2' '
464 client_view "//depot/... //client/..." &&
468 p4 delete dir2/filecollide &&
469 p4 submit -d "remove dir2/filecollide"
473 # no filecollide, got deleted with dir2
474 test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
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 update 1' '
485 client_view "//depot/dir1/... //client/dir1/..." &&
489 p4 open dir1/filecollide &&
490 echo dir1/filecollide update >dir1/filecollide &&
491 p4 submit -d "update dir1/filecollide"
495 # still no filecollide, dir2 still wins with the deletion even though the
496 # change to dir1 is more recent
497 test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
498 client_view "//depot/dir1/... //client/..." \
499 "+//depot/dir2/... //client/..." &&
500 files="file11 file12 file21 file22" &&
501 client_verify $files &&
502 test_when_finished cleanup_git &&
503 git p4 clone --use-client-spec --dest="$git" //depot &&
507 test_expect_success 'overlay collision delete filecollides' '
508 client_view "//depot/... //client/..." &&
512 p4 delete dir1/filecollide dir2/filecollide &&
513 p4 submit -d "remove filecollides"
518 # Overlays as part of sync, rather than initial checkout:
519 # 1. add a file in dir1
520 # 2. sync to include it
521 # 3. add same file in dir2
522 # 4. sync, make sure content switches as dir2 has priority
523 # 5. add another file in dir1
525 # 7. add/delete same file in dir2
526 # 8. sync, make sure it disappears, again dir2 wins
541 test_expect_success 'overlay sync: add colA in dir1' '
542 client_view "//depot/dir1/... //client/dir1/..." &&
546 echo dir1/colA >dir1/colA &&
548 p4 submit -d dir1/colA
552 test_expect_success 'overlay sync: initial git checkout' '
553 client_view "//depot/dir1/... //client/..." \
554 "+//depot/dir2/... //client/..." &&
555 files="file11 file12 file21 file22 colA" &&
556 echo dir1/colA >actual &&
557 client_verify $files &&
558 test_cmp actual "$cli"/colA &&
559 git p4 clone --use-client-spec --dest="$git" //depot &&
561 test_cmp actual "$git"/colA
564 test_expect_success 'overlay sync: add colA in dir2' '
565 client_view "//depot/dir2/... //client/dir2/..." &&
569 echo dir2/colA >dir2/colA &&
571 p4 submit -d dir2/colA
575 test_expect_success 'overlay sync: colA content switch' '
576 client_view "//depot/dir1/... //client/..." \
577 "+//depot/dir2/... //client/..." &&
578 files="file11 file12 file21 file22 colA" &&
579 echo dir2/colA >actual &&
580 client_verify $files &&
581 test_cmp actual "$cli"/colA &&
584 git p4 sync --use-client-spec &&
585 git merge --ff-only p4/master
588 test_cmp actual "$git"/colA
591 test_expect_success 'overlay sync: add colB in dir1' '
592 client_view "//depot/dir1/... //client/dir1/..." &&
596 echo dir1/colB >dir1/colB &&
598 p4 submit -d dir1/colB
602 test_expect_success 'overlay sync: colB appears' '
603 client_view "//depot/dir1/... //client/..." \
604 "+//depot/dir2/... //client/..." &&
605 files="file11 file12 file21 file22 colA colB" &&
606 echo dir1/colB >actual &&
607 client_verify $files &&
608 test_cmp actual "$cli"/colB &&
611 git p4 sync --use-client-spec &&
612 git merge --ff-only p4/master
615 test_cmp actual "$git"/colB
618 test_expect_success 'overlay sync: add/delete colB in dir2' '
619 client_view "//depot/dir2/... //client/dir2/..." &&
623 echo dir2/colB >dir2/colB &&
625 p4 submit -d dir2/colB &&
626 p4 delete dir2/colB &&
627 p4 submit -d "delete dir2/colB"
631 test_expect_success 'overlay sync: colB disappears' '
632 client_view "//depot/dir1/... //client/..." \
633 "+//depot/dir2/... //client/..." &&
634 files="file11 file12 file21 file22 colA" &&
635 client_verify $files &&
636 test_when_finished cleanup_git &&
639 git p4 sync --use-client-spec &&
640 git merge --ff-only p4/master
645 test_expect_success 'overlay sync: cleanup' '
646 client_view "//depot/... //client/..." &&
650 p4 delete dir1/colA dir2/colA dir1/colB &&
651 p4 submit -d "remove overlay sync files"
656 # Overlay tests again, but swapped so dir1 has priority.
657 # 1. add a file in dir1
658 # 2. sync to include it
659 # 3. add same file in dir2
660 # 4. sync, make sure content does not switch
661 # 5. add another file in dir1
663 # 7. add/delete same file in dir2
664 # 8. sync, make sure it is still there
679 test_expect_success 'overlay sync swap: add colA in dir1' '
680 client_view "//depot/dir1/... //client/dir1/..." &&
684 echo dir1/colA >dir1/colA &&
686 p4 submit -d dir1/colA
690 test_expect_success 'overlay sync swap: initial git checkout' '
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 &&
697 git p4 clone --use-client-spec --dest="$git" //depot &&
699 test_cmp actual "$git"/colA
702 test_expect_success 'overlay sync swap: add colA in dir2' '
703 client_view "//depot/dir2/... //client/dir2/..." &&
707 echo dir2/colA >dir2/colA &&
709 p4 submit -d dir2/colA
713 test_expect_failure 'overlay sync swap: colA no content switch' '
714 client_view "//depot/dir2/... //client/..." \
715 "+//depot/dir1/... //client/..." &&
716 files="file11 file12 file21 file22 colA" &&
717 echo dir1/colA >actual &&
718 client_verify $files &&
719 test_cmp actual "$cli"/colA &&
722 git p4 sync --use-client-spec &&
723 git merge --ff-only p4/master
726 test_cmp actual "$git"/colA
729 test_expect_success 'overlay sync swap: add colB in dir1' '
730 client_view "//depot/dir1/... //client/dir1/..." &&
734 echo dir1/colB >dir1/colB &&
736 p4 submit -d dir1/colB
740 test_expect_success 'overlay sync swap: colB appears' '
741 client_view "//depot/dir2/... //client/..." \
742 "+//depot/dir1/... //client/..." &&
743 files="file11 file12 file21 file22 colA colB" &&
744 echo dir1/colB >actual &&
745 client_verify $files &&
746 test_cmp actual "$cli"/colB &&
749 git p4 sync --use-client-spec &&
750 git merge --ff-only p4/master
753 test_cmp actual "$git"/colB
756 test_expect_success 'overlay sync swap: add/delete colB in dir2' '
757 client_view "//depot/dir2/... //client/dir2/..." &&
761 echo dir2/colB >dir2/colB &&
763 p4 submit -d dir2/colB &&
764 p4 delete dir2/colB &&
765 p4 submit -d "delete dir2/colB"
769 test_expect_failure 'overlay sync swap: colB no change' '
770 client_view "//depot/dir2/... //client/..." \
771 "+//depot/dir1/... //client/..." &&
772 files="file11 file12 file21 file22 colA colB" &&
773 echo dir1/colB >actual &&
774 client_verify $files &&
775 test_cmp actual "$cli"/colB &&
776 test_when_finished cleanup_git &&
779 git p4 sync --use-client-spec &&
780 git merge --ff-only p4/master
783 test_cmp actual "$cli"/colB
786 test_expect_success 'overlay sync swap: cleanup' '
787 client_view "//depot/... //client/..." &&
791 p4 delete dir1/colA dir2/colA dir1/colB &&
792 p4 submit -d "remove overlay sync files"
797 # Rename directories to test quoting in depot-side mappings
806 test_expect_success 'rename files to introduce spaces' '
807 client_view "//depot/... //client/..." &&
808 client_verify dir1/file11 dir1/file12 \
809 dir2/file21 dir2/file22 &&
813 p4 move dir1/... "dir 1"/... &&
815 p4 move dir2/... "dir 2"/... &&
816 p4 submit -d "rename with spaces"
818 client_verify "dir 1/file11" "dir 1/file12" \
819 "dir 2/file21" "dir 2/file22"
822 test_expect_success 'quotes on lhs only' '
823 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
824 files="cdir1/file11 cdir1/file12" &&
825 client_verify $files &&
826 test_when_finished cleanup_git &&
827 git p4 clone --use-client-spec --dest="$git" //depot &&
831 test_expect_success 'quotes on both sides' '
832 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
833 client_verify "cdir 1/file11" "cdir 1/file12" &&
834 test_when_finished cleanup_git &&
835 git p4 clone --use-client-spec --dest="$git" //depot &&
836 git_verify "cdir 1/file11" "cdir 1/file12"
839 test_expect_success 'kill p4d' '