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 dir
1/file11 dir
1/file12 \
85 dir
2/file21 dir
2/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 # see t9800 for the non-client-spec case, and the rest of the wildcard tests
378 test_expect_success
'wildcard files submit back to p4, client-spec case' '
379 client_view "//depot/... //client/..." &&
380 test_when_finished cleanup_git &&
381 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
384 echo git-wild-hash >dir1/git-wild#hash &&
385 echo git-wild-star >dir1/git-wild\*star &&
386 echo git-wild-at >dir1/git-wild@at &&
387 echo git-wild-percent >dir1/git-wild%percent &&
388 git add dir1/git-wild* &&
389 git commit -m "add some wildcard filenames" &&
390 git config git-p4.skipSubmitEditCheck true &&
395 test_path_is_file dir1/git-wild#hash &&
396 test_path_is_file dir1/git-wild\*star &&
397 test_path_is_file dir1/git-wild@at &&
398 test_path_is_file dir1/git-wild%percent
401 # delete these carefully, cannot just do "p4 delete"
402 # on files with wildcards; but git-p4 knows how
404 git rm dir1/git-wild* &&
405 git commit -m "clean up the wildcards" &&
410 test_expect_success
'reinit depot' '
415 p4 submit -d "delete all files" &&
421 # What happens when two files of the same name are overlayed together?
422 # The last-listed file should take preference.
434 test_expect_success
'overlay collision setup' '
435 client_view "//depot/... //client/..." &&
439 echo dir1/filecollide >dir1/filecollide &&
440 p4 add dir1/filecollide &&
441 p4 submit -d dir1/filecollide &&
442 echo dir2/filecollide >dir2/filecollide &&
443 p4 add dir2/filecollide &&
444 p4 submit -d dir2/filecollide
448 test_expect_success
'overlay collision 1 to 2' '
449 client_view "//depot/dir1/... //client/..." \
450 "+//depot/dir2/... //client/..." &&
451 files="file11 file12 file21 file22 filecollide" &&
452 echo dir2/filecollide >actual &&
453 client_verify $files &&
454 test_cmp actual "$cli"/filecollide &&
455 test_when_finished cleanup_git &&
456 git p4 clone --use-client-spec --dest="$git" //depot &&
458 test_cmp actual "$git"/filecollide
461 test_expect_failure
'overlay collision 2 to 1' '
462 client_view "//depot/dir2/... //client/..." \
463 "+//depot/dir1/... //client/..." &&
464 files="file11 file12 file21 file22 filecollide" &&
465 echo dir1/filecollide >actual &&
466 client_verify $files &&
467 test_cmp actual "$cli"/filecollide &&
468 test_when_finished cleanup_git &&
469 git p4 clone --use-client-spec --dest="$git" //depot &&
471 test_cmp actual "$git"/filecollide
474 test_expect_success
'overlay collision delete 2' '
475 client_view "//depot/... //client/..." &&
479 p4 delete dir2/filecollide &&
480 p4 submit -d "remove dir2/filecollide"
484 # no filecollide, got deleted with dir2
485 test_expect_failure
'overlay collision 1 to 2, but 2 deleted' '
486 client_view "//depot/dir1/... //client/..." \
487 "+//depot/dir2/... //client/..." &&
488 files="file11 file12 file21 file22" &&
489 client_verify $files &&
490 test_when_finished cleanup_git &&
491 git p4 clone --use-client-spec --dest="$git" //depot &&
495 test_expect_success
'overlay collision update 1' '
496 client_view "//depot/dir1/... //client/dir1/..." &&
500 p4 open dir1/filecollide &&
501 echo dir1/filecollide update >dir1/filecollide &&
502 p4 submit -d "update dir1/filecollide"
506 # still no filecollide, dir2 still wins with the deletion even though the
507 # change to dir1 is more recent
508 test_expect_failure
'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
509 client_view "//depot/dir1/... //client/..." \
510 "+//depot/dir2/... //client/..." &&
511 files="file11 file12 file21 file22" &&
512 client_verify $files &&
513 test_when_finished cleanup_git &&
514 git p4 clone --use-client-spec --dest="$git" //depot &&
518 test_expect_success
'overlay collision delete filecollides' '
519 client_view "//depot/... //client/..." &&
523 p4 delete dir1/filecollide dir2/filecollide &&
524 p4 submit -d "remove filecollides"
529 # Overlays as part of sync, rather than initial checkout:
530 # 1. add a file in dir1
531 # 2. sync to include it
532 # 3. add same file in dir2
533 # 4. sync, make sure content switches as dir2 has priority
534 # 5. add another file in dir1
536 # 7. add/delete same file in dir2
537 # 8. sync, make sure it disappears, again dir2 wins
552 test_expect_success
'overlay sync: add colA in dir1' '
553 client_view "//depot/dir1/... //client/dir1/..." &&
557 echo dir1/colA >dir1/colA &&
559 p4 submit -d dir1/colA
563 test_expect_success
'overlay sync: initial git checkout' '
564 client_view "//depot/dir1/... //client/..." \
565 "+//depot/dir2/... //client/..." &&
566 files="file11 file12 file21 file22 colA" &&
567 echo dir1/colA >actual &&
568 client_verify $files &&
569 test_cmp actual "$cli"/colA &&
570 git p4 clone --use-client-spec --dest="$git" //depot &&
572 test_cmp actual "$git"/colA
575 test_expect_success
'overlay sync: add colA in dir2' '
576 client_view "//depot/dir2/... //client/dir2/..." &&
580 echo dir2/colA >dir2/colA &&
582 p4 submit -d dir2/colA
586 test_expect_success
'overlay sync: colA content switch' '
587 client_view "//depot/dir1/... //client/..." \
588 "+//depot/dir2/... //client/..." &&
589 files="file11 file12 file21 file22 colA" &&
590 echo dir2/colA >actual &&
591 client_verify $files &&
592 test_cmp actual "$cli"/colA &&
595 git p4 sync --use-client-spec &&
596 git merge --ff-only p4/master
599 test_cmp actual "$git"/colA
602 test_expect_success
'overlay sync: add colB in dir1' '
603 client_view "//depot/dir1/... //client/dir1/..." &&
607 echo dir1/colB >dir1/colB &&
609 p4 submit -d dir1/colB
613 test_expect_success
'overlay sync: colB appears' '
614 client_view "//depot/dir1/... //client/..." \
615 "+//depot/dir2/... //client/..." &&
616 files="file11 file12 file21 file22 colA colB" &&
617 echo dir1/colB >actual &&
618 client_verify $files &&
619 test_cmp actual "$cli"/colB &&
622 git p4 sync --use-client-spec &&
623 git merge --ff-only p4/master
626 test_cmp actual "$git"/colB
629 test_expect_success
'overlay sync: add/delete colB in dir2' '
630 client_view "//depot/dir2/... //client/dir2/..." &&
634 echo dir2/colB >dir2/colB &&
636 p4 submit -d dir2/colB &&
637 p4 delete dir2/colB &&
638 p4 submit -d "delete dir2/colB"
642 test_expect_success
'overlay sync: colB disappears' '
643 client_view "//depot/dir1/... //client/..." \
644 "+//depot/dir2/... //client/..." &&
645 files="file11 file12 file21 file22 colA" &&
646 client_verify $files &&
647 test_when_finished cleanup_git &&
650 git p4 sync --use-client-spec &&
651 git merge --ff-only p4/master
656 test_expect_success
'overlay sync: cleanup' '
657 client_view "//depot/... //client/..." &&
661 p4 delete dir1/colA dir2/colA dir1/colB &&
662 p4 submit -d "remove overlay sync files"
667 # Overlay tests again, but swapped so dir1 has priority.
668 # 1. add a file in dir1
669 # 2. sync to include it
670 # 3. add same file in dir2
671 # 4. sync, make sure content does not switch
672 # 5. add another file in dir1
674 # 7. add/delete same file in dir2
675 # 8. sync, make sure it is still there
690 test_expect_success
'overlay sync swap: add colA in dir1' '
691 client_view "//depot/dir1/... //client/dir1/..." &&
695 echo dir1/colA >dir1/colA &&
697 p4 submit -d dir1/colA
701 test_expect_success
'overlay sync swap: initial git checkout' '
702 client_view "//depot/dir2/... //client/..." \
703 "+//depot/dir1/... //client/..." &&
704 files="file11 file12 file21 file22 colA" &&
705 echo dir1/colA >actual &&
706 client_verify $files &&
707 test_cmp actual "$cli"/colA &&
708 git p4 clone --use-client-spec --dest="$git" //depot &&
710 test_cmp actual "$git"/colA
713 test_expect_success
'overlay sync swap: add colA in dir2' '
714 client_view "//depot/dir2/... //client/dir2/..." &&
718 echo dir2/colA >dir2/colA &&
720 p4 submit -d dir2/colA
724 test_expect_failure
'overlay sync swap: colA no content switch' '
725 client_view "//depot/dir2/... //client/..." \
726 "+//depot/dir1/... //client/..." &&
727 files="file11 file12 file21 file22 colA" &&
728 echo dir1/colA >actual &&
729 client_verify $files &&
730 test_cmp actual "$cli"/colA &&
733 git p4 sync --use-client-spec &&
734 git merge --ff-only p4/master
737 test_cmp actual "$git"/colA
740 test_expect_success
'overlay sync swap: add colB in dir1' '
741 client_view "//depot/dir1/... //client/dir1/..." &&
745 echo dir1/colB >dir1/colB &&
747 p4 submit -d dir1/colB
751 test_expect_success
'overlay sync swap: colB appears' '
752 client_view "//depot/dir2/... //client/..." \
753 "+//depot/dir1/... //client/..." &&
754 files="file11 file12 file21 file22 colA colB" &&
755 echo dir1/colB >actual &&
756 client_verify $files &&
757 test_cmp actual "$cli"/colB &&
760 git p4 sync --use-client-spec &&
761 git merge --ff-only p4/master
764 test_cmp actual "$git"/colB
767 test_expect_success
'overlay sync swap: add/delete colB in dir2' '
768 client_view "//depot/dir2/... //client/dir2/..." &&
772 echo dir2/colB >dir2/colB &&
774 p4 submit -d dir2/colB &&
775 p4 delete dir2/colB &&
776 p4 submit -d "delete dir2/colB"
780 test_expect_failure
'overlay sync swap: colB no change' '
781 client_view "//depot/dir2/... //client/..." \
782 "+//depot/dir1/... //client/..." &&
783 files="file11 file12 file21 file22 colA colB" &&
784 echo dir1/colB >actual &&
785 client_verify $files &&
786 test_cmp actual "$cli"/colB &&
787 test_when_finished cleanup_git &&
790 git p4 sync --use-client-spec &&
791 git merge --ff-only p4/master
794 test_cmp actual "$cli"/colB
797 test_expect_success
'overlay sync swap: cleanup' '
798 client_view "//depot/... //client/..." &&
802 p4 delete dir1/colA dir2/colA dir1/colB &&
803 p4 submit -d "remove overlay sync files"
808 # Rename directories to test quoting in depot-side mappings
817 test_expect_success
'rename files to introduce spaces' '
818 client_view "//depot/... //client/..." &&
819 client_verify dir1/file11 dir1/file12 \
820 dir2/file21 dir2/file22 &&
824 p4 move dir1/... "dir 1"/... &&
826 p4 move dir2/... "dir 2"/... &&
827 p4 submit -d "rename with spaces"
829 client_verify "dir 1/file11" "dir 1/file12" \
830 "dir 2/file21" "dir 2/file22"
833 test_expect_success
'quotes on lhs only' '
834 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
835 files="cdir1/file11 cdir1/file12" &&
836 client_verify $files &&
837 test_when_finished cleanup_git &&
838 git p4 clone --use-client-spec --dest="$git" //depot &&
842 test_expect_success
'quotes on both sides' '
843 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
844 client_verify "cdir 1/file11" "cdir 1/file12" &&
845 test_when_finished cleanup_git &&
846 git p4 clone --use-client-spec --dest="$git" //depot &&
847 git_verify "cdir 1/file11" "cdir 1/file12"
850 test_expect_success
'kill p4d' '