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 &&
353 test ! -w dir1/file11a
357 test_expect_success 'subdir clone, submit rename' '
358 client_view "//depot/... //client/..." &&
359 test_when_finished cleanup_git &&
360 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
363 git config git-p4.skipSubmitEdit true &&
364 git config git-p4.detectRenames true &&
365 git mv dir1/file13 dir1/file13a &&
366 git commit -m "rename dir1/file13 to dir1/file13a" &&
371 test_path_is_missing dir1/file13 &&
372 test_path_is_file dir1/file13a &&
373 test ! -w dir1/file13a
377 test_expect_success 'reinit depot' '
382 p4 submit -d "delete all files" &&
388 # What happens when two files of the same name are overlayed together?
389 # The last-listed file should take preference.
401 test_expect_success 'overlay collision setup' '
402 client_view "//depot/... //client/..." &&
406 echo dir1/filecollide >dir1/filecollide &&
407 p4 add dir1/filecollide &&
408 p4 submit -d dir1/filecollide &&
409 echo dir2/filecollide >dir2/filecollide &&
410 p4 add dir2/filecollide &&
411 p4 submit -d dir2/filecollide
415 test_expect_success 'overlay collision 1 to 2' '
416 client_view "//depot/dir1/... //client/..." \
417 "+//depot/dir2/... //client/..." &&
418 files="file11 file12 file21 file22 filecollide" &&
419 echo dir2/filecollide >actual &&
420 client_verify $files &&
421 test_cmp actual "$cli"/filecollide &&
422 test_when_finished cleanup_git &&
423 git p4 clone --use-client-spec --dest="$git" //depot &&
425 test_cmp actual "$git"/filecollide
428 test_expect_failure 'overlay collision 2 to 1' '
429 client_view "//depot/dir2/... //client/..." \
430 "+//depot/dir1/... //client/..." &&
431 files="file11 file12 file21 file22 filecollide" &&
432 echo dir1/filecollide >actual &&
433 client_verify $files &&
434 test_cmp actual "$cli"/filecollide &&
435 test_when_finished cleanup_git &&
436 git p4 clone --use-client-spec --dest="$git" //depot &&
438 test_cmp actual "$git"/filecollide
441 test_expect_success 'overlay collision delete 2' '
442 client_view "//depot/... //client/..." &&
446 p4 delete dir2/filecollide &&
447 p4 submit -d "remove dir2/filecollide"
451 # no filecollide, got deleted with dir2
452 test_expect_failure 'overlay collision 1 to 2, but 2 deleted' '
453 client_view "//depot/dir1/... //client/..." \
454 "+//depot/dir2/... //client/..." &&
455 files="file11 file12 file21 file22" &&
456 client_verify $files &&
457 test_when_finished cleanup_git &&
458 git p4 clone --use-client-spec --dest="$git" //depot &&
462 test_expect_success 'overlay collision update 1' '
463 client_view "//depot/dir1/... //client/dir1/..." &&
467 p4 open dir1/filecollide &&
468 echo dir1/filecollide update >dir1/filecollide &&
469 p4 submit -d "update dir1/filecollide"
473 # still no filecollide, dir2 still wins with the deletion even though the
474 # change to dir1 is more recent
475 test_expect_failure 'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
476 client_view "//depot/dir1/... //client/..." \
477 "+//depot/dir2/... //client/..." &&
478 files="file11 file12 file21 file22" &&
479 client_verify $files &&
480 test_when_finished cleanup_git &&
481 git p4 clone --use-client-spec --dest="$git" //depot &&
485 test_expect_success 'overlay collision delete filecollides' '
486 client_view "//depot/... //client/..." &&
490 p4 delete dir1/filecollide dir2/filecollide &&
491 p4 submit -d "remove filecollides"
496 # Overlays as part of sync, rather than initial checkout:
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 switches as dir2 has priority
501 # 5. add another file in dir1
503 # 7. add/delete same file in dir2
504 # 8. sync, make sure it disappears, again dir2 wins
519 test_expect_success 'overlay sync: 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: initial git checkout' '
531 client_view "//depot/dir1/... //client/..." \
532 "+//depot/dir2/... //client/..." &&
533 files="file11 file12 file21 file22 colA" &&
534 echo dir1/colA >actual &&
535 client_verify $files &&
536 test_cmp actual "$cli"/colA &&
537 git p4 clone --use-client-spec --dest="$git" //depot &&
539 test_cmp actual "$git"/colA
542 test_expect_success 'overlay sync: 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_success 'overlay sync: colA content switch' '
554 client_view "//depot/dir1/... //client/..." \
555 "+//depot/dir2/... //client/..." &&
556 files="file11 file12 file21 file22 colA" &&
557 echo dir2/colA >actual &&
558 client_verify $files &&
559 test_cmp actual "$cli"/colA &&
562 git p4 sync --use-client-spec &&
563 git merge --ff-only p4/master
566 test_cmp actual "$git"/colA
569 test_expect_success 'overlay sync: 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: colB appears' '
581 client_view "//depot/dir1/... //client/..." \
582 "+//depot/dir2/... //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 git p4 sync --use-client-spec &&
590 git merge --ff-only p4/master
593 test_cmp actual "$git"/colB
596 test_expect_success 'overlay sync: 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_success 'overlay sync: colB disappears' '
610 client_view "//depot/dir1/... //client/..." \
611 "+//depot/dir2/... //client/..." &&
612 files="file11 file12 file21 file22 colA" &&
613 client_verify $files &&
614 test_when_finished cleanup_git &&
617 git p4 sync --use-client-spec &&
618 git merge --ff-only p4/master
623 test_expect_success 'overlay sync: cleanup' '
624 client_view "//depot/... //client/..." &&
628 p4 delete dir1/colA dir2/colA dir1/colB &&
629 p4 submit -d "remove overlay sync files"
634 # Overlay tests again, but swapped so dir1 has priority.
635 # 1. add a file in dir1
636 # 2. sync to include it
637 # 3. add same file in dir2
638 # 4. sync, make sure content does not switch
639 # 5. add another file in dir1
641 # 7. add/delete same file in dir2
642 # 8. sync, make sure it is still there
657 test_expect_success 'overlay sync swap: add colA in dir1' '
658 client_view "//depot/dir1/... //client/dir1/..." &&
662 echo dir1/colA >dir1/colA &&
664 p4 submit -d dir1/colA
668 test_expect_success 'overlay sync swap: initial git checkout' '
669 client_view "//depot/dir2/... //client/..." \
670 "+//depot/dir1/... //client/..." &&
671 files="file11 file12 file21 file22 colA" &&
672 echo dir1/colA >actual &&
673 client_verify $files &&
674 test_cmp actual "$cli"/colA &&
675 git p4 clone --use-client-spec --dest="$git" //depot &&
677 test_cmp actual "$git"/colA
680 test_expect_success 'overlay sync swap: add colA in dir2' '
681 client_view "//depot/dir2/... //client/dir2/..." &&
685 echo dir2/colA >dir2/colA &&
687 p4 submit -d dir2/colA
691 test_expect_failure 'overlay sync swap: colA no content switch' '
692 client_view "//depot/dir2/... //client/..." \
693 "+//depot/dir1/... //client/..." &&
694 files="file11 file12 file21 file22 colA" &&
695 echo dir1/colA >actual &&
696 client_verify $files &&
697 test_cmp actual "$cli"/colA &&
700 git p4 sync --use-client-spec &&
701 git merge --ff-only p4/master
704 test_cmp actual "$git"/colA
707 test_expect_success 'overlay sync swap: add colB in dir1' '
708 client_view "//depot/dir1/... //client/dir1/..." &&
712 echo dir1/colB >dir1/colB &&
714 p4 submit -d dir1/colB
718 test_expect_success 'overlay sync swap: colB appears' '
719 client_view "//depot/dir2/... //client/..." \
720 "+//depot/dir1/... //client/..." &&
721 files="file11 file12 file21 file22 colA colB" &&
722 echo dir1/colB >actual &&
723 client_verify $files &&
724 test_cmp actual "$cli"/colB &&
727 git p4 sync --use-client-spec &&
728 git merge --ff-only p4/master
731 test_cmp actual "$git"/colB
734 test_expect_success 'overlay sync swap: add/delete colB in dir2' '
735 client_view "//depot/dir2/... //client/dir2/..." &&
739 echo dir2/colB >dir2/colB &&
741 p4 submit -d dir2/colB &&
742 p4 delete dir2/colB &&
743 p4 submit -d "delete dir2/colB"
747 test_expect_failure 'overlay sync swap: colB no change' '
748 client_view "//depot/dir2/... //client/..." \
749 "+//depot/dir1/... //client/..." &&
750 files="file11 file12 file21 file22 colA colB" &&
751 echo dir1/colB >actual &&
752 client_verify $files &&
753 test_cmp actual "$cli"/colB &&
754 test_when_finished cleanup_git &&
757 git p4 sync --use-client-spec &&
758 git merge --ff-only p4/master
761 test_cmp actual "$cli"/colB
764 test_expect_success 'overlay sync swap: cleanup' '
765 client_view "//depot/... //client/..." &&
769 p4 delete dir1/colA dir2/colA dir1/colB &&
770 p4 submit -d "remove overlay sync files"
775 # Rename directories to test quoting in depot-side mappings
784 test_expect_success 'rename files to introduce spaces' '
785 client_view "//depot/... //client/..." &&
786 client_verify dir1/file11 dir1/file12 \
787 dir2/file21 dir2/file22 &&
791 p4 move dir1/... "dir 1"/... &&
793 p4 move dir2/... "dir 2"/... &&
794 p4 submit -d "rename with spaces"
796 client_verify "dir 1/file11" "dir 1/file12" \
797 "dir 2/file21" "dir 2/file22"
800 test_expect_success 'quotes on lhs only' '
801 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
802 files="cdir1/file11 cdir1/file12" &&
803 client_verify $files &&
804 test_when_finished cleanup_git &&
805 git p4 clone --use-client-spec --dest="$git" //depot &&
809 test_expect_success 'quotes on both sides' '
810 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
811 client_verify "cdir 1/file11" "cdir 1/file12" &&
812 test_when_finished cleanup_git &&
813 git p4 clone --use-client-spec --dest="$git" //depot &&
814 git_verify "cdir 1/file11" "cdir 1/file12"
817 test_expect_success 'kill p4d' '