3 test_description
='git p4 client view'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'start p4d' '
13 # Verify these files exist, exactly. Caller creates
14 # a list of files in file "files".
20 test_path_is_file
"$arg" &&
24 test_line_count
= $num files
28 # Sync up the p4 client, make sure the given files (and only
35 find .
-type f
! -name files
>files
&&
36 check_files_exist
"$@"
41 # Make sure the named files, exactly, exist.
46 git ls-files
>files
&&
47 check_files_exist
"$@"
62 echo dir
$d/file$d$f >dir
$d/file$d$f &&
63 p4 add dir
$d/file$d$f &&
64 p4 submit
-d "dir$d/file$d$f"
67 find .
-type f
! -name files
>files
&&
68 check_files_exist dir
1/file11 dir
1/file12 \
69 dir
2/file21 dir
2/file22
72 test_expect_success
'init depot' '
80 test_expect_success
'view wildcard %%n' '
81 client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
82 test_when_finished cleanup_git &&
83 git p4 clone --use-client-spec --dest="$git" //depot
86 test_expect_success
'view wildcard *' '
87 client_view "//depot/*/bar/... //client/*/bar/..." &&
88 test_when_finished cleanup_git &&
89 git p4 clone --use-client-spec --dest="$git" //depot
92 test_expect_success
'wildcard ... in the middle' '
93 client_view "//depot/.../file11 //client/.../file11" &&
94 test_when_finished cleanup_git &&
95 git p4 clone --use-client-spec --dest="$git" //depot
98 test_expect_success
'wildcard ... in the middle and at the end' '
99 client_view "//depot/.../a/... //client/.../a/..." &&
100 test_when_finished cleanup_git &&
101 git p4 clone --use-client-spec --dest="$git" //depot
104 test_expect_success
'basic map' '
105 client_view "//depot/dir1/... //client/cli1/..." &&
106 files="cli1/file11 cli1/file12" &&
107 client_verify $files &&
108 test_when_finished cleanup_git &&
109 git p4 clone --use-client-spec --dest="$git" //depot &&
113 test_expect_success
'client view with no mappings' '
116 test_when_finished cleanup_git &&
117 git p4 clone --use-client-spec --dest="$git" //depot &&
121 test_expect_success
'single file map' '
122 client_view "//depot/dir1/file11 //client/file11" &&
124 client_verify $files &&
125 test_when_finished cleanup_git &&
126 git p4 clone --use-client-spec --dest="$git" //depot &&
130 test_expect_success
'later mapping takes precedence (entire repo)' '
131 client_view "//depot/dir1/... //client/cli1/..." \
132 "//depot/... //client/cli2/..." &&
133 files="cli2/dir1/file11 cli2/dir1/file12
134 cli2/dir2/file21 cli2/dir2/file22" &&
135 client_verify $files &&
136 test_when_finished cleanup_git &&
137 git p4 clone --use-client-spec --dest="$git" //depot &&
141 test_expect_success
'later mapping takes precedence (partial repo)' '
142 client_view "//depot/dir1/... //client/..." \
143 "//depot/dir2/... //client/..." &&
144 files="file21 file22" &&
145 client_verify $files &&
146 test_when_finished cleanup_git &&
147 git p4 clone --use-client-spec --dest="$git" //depot &&
151 # Reading the view backwards,
153 # dir1 cannot go to cli12 since it was filled by dir2
154 # dir1 also does not go to cli3, since the second rule
155 # noticed that it matched, but was already filled
156 test_expect_success
'depot path matching rejected client path' '
157 client_view "//depot/dir1/... //client/cli3/..." \
158 "//depot/dir1/... //client/cli12/..." \
159 "//depot/dir2/... //client/cli12/..." &&
160 files="cli12/file21 cli12/file22" &&
161 client_verify $files &&
162 test_when_finished cleanup_git &&
163 git p4 clone --use-client-spec --dest="$git" //depot &&
167 # since both have the same //client/..., the exclusion
168 # rule keeps everything out
169 test_expect_success
'exclusion wildcard, client rhs same (odd)' '
170 client_view "//depot/... //client/..." \
171 "-//depot/dir2/... //client/..." &&
173 test_when_finished cleanup_git &&
174 git p4 clone --use-client-spec --dest="$git" //depot &&
178 test_expect_success
'exclusion wildcard, client rhs different (normal)' '
179 client_view "//depot/... //client/..." \
180 "-//depot/dir2/... //client/dir2/..." &&
181 files="dir1/file11 dir1/file12" &&
182 client_verify $files &&
183 test_when_finished cleanup_git &&
184 git p4 clone --use-client-spec --dest="$git" //depot &&
188 test_expect_success
'exclusion single file' '
189 client_view "//depot/... //client/..." \
190 "-//depot/dir2/file22 //client/file22" &&
191 files="dir1/file11 dir1/file12 dir2/file21" &&
192 client_verify $files &&
193 test_when_finished cleanup_git &&
194 git p4 clone --use-client-spec --dest="$git" //depot &&
198 test_expect_success
'overlay wildcard' '
199 client_view "//depot/dir1/... //client/cli/..." \
200 "+//depot/dir2/... //client/cli/..." &&
201 files="cli/file11 cli/file12 cli/file21 cli/file22" &&
202 client_verify $files &&
203 test_when_finished cleanup_git &&
204 git p4 clone --use-client-spec --dest="$git" //depot &&
208 test_expect_success
'overlay single file' '
209 client_view "//depot/dir1/... //client/cli/..." \
210 "+//depot/dir2/file21 //client/cli/file21" &&
211 files="cli/file11 cli/file12 cli/file21" &&
212 client_verify $files &&
213 test_when_finished cleanup_git &&
214 git p4 clone --use-client-spec --dest="$git" //depot &&
218 test_expect_success
'exclusion with later inclusion' '
219 client_view "//depot/... //client/..." \
220 "-//depot/dir2/... //client/dir2/..." \
221 "//depot/dir2/... //client/dir2incl/..." &&
222 files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
223 client_verify $files &&
224 test_when_finished cleanup_git &&
225 git p4 clone --use-client-spec --dest="$git" //depot &&
229 test_expect_success
'quotes on rhs only' '
230 client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
231 client_verify "cdir 1/file11" "cdir 1/file12" &&
232 test_when_finished cleanup_git &&
233 git p4 clone --use-client-spec --dest="$git" //depot &&
234 git_verify "cdir 1/file11" "cdir 1/file12"
241 # clone sets variable
242 test_expect_success
'clone --use-client-spec sets useClientSpec' '
243 client_view "//depot/... //client/..." &&
244 test_when_finished cleanup_git &&
245 git p4 clone --use-client-spec --dest="$git" //depot &&
248 git config --bool git-p4.useClientSpec >actual &&
254 # clone just a subdir of the client spec
255 test_expect_success
'subdir clone' '
256 client_view "//depot/... //client/..." &&
257 files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
258 client_verify $files &&
259 test_when_finished cleanup_git &&
260 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
261 git_verify dir1/file11 dir1/file12
265 # submit back, see what happens: five cases
267 test_expect_success
'subdir clone, submit modify' '
268 client_view "//depot/... //client/..." &&
269 test_when_finished cleanup_git &&
270 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
273 git config git-p4.skipSubmitEdit true &&
274 echo line >>dir1/file12 &&
275 git add dir1/file12 &&
276 git commit -m dir1/file12 &&
281 test_path_is_file dir1/file12 &&
282 test_line_count = 2 dir1/file12
286 test_expect_success
'subdir clone, submit add' '
287 client_view "//depot/... //client/..." &&
288 test_when_finished cleanup_git &&
289 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
292 git config git-p4.skipSubmitEdit true &&
293 echo file13 >dir1/file13 &&
294 git add dir1/file13 &&
295 git commit -m dir1/file13 &&
300 test_path_is_file dir1/file13
304 test_expect_success
'subdir clone, submit delete' '
305 client_view "//depot/... //client/..." &&
306 test_when_finished cleanup_git &&
307 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
310 git config git-p4.skipSubmitEdit true &&
311 git rm dir1/file12 &&
312 git commit -m "delete dir1/file12" &&
317 test_path_is_missing dir1/file12
321 test_expect_success
'subdir clone, submit copy' '
322 client_view "//depot/... //client/..." &&
323 test_when_finished cleanup_git &&
324 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
327 git config git-p4.skipSubmitEdit true &&
328 git config git-p4.detectCopies true &&
329 cp dir1/file11 dir1/file11a &&
330 git add dir1/file11a &&
331 git commit -m "copy to dir1/file11a" &&
336 test_path_is_file dir1/file11a &&
337 ! is_cli_file_writeable dir1/file11a
341 test_expect_success
'subdir clone, submit rename' '
342 client_view "//depot/... //client/..." &&
343 test_when_finished cleanup_git &&
344 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
347 git config git-p4.skipSubmitEdit true &&
348 git config git-p4.detectRenames true &&
349 git mv dir1/file13 dir1/file13a &&
350 git commit -m "rename dir1/file13 to dir1/file13a" &&
355 test_path_is_missing dir1/file13 &&
356 test_path_is_file dir1/file13a &&
357 ! is_cli_file_writeable dir1/file13a
361 # see t9800 for the non-client-spec case, and the rest of the wildcard tests
362 test_expect_success
'wildcard files submit back to p4, client-spec case' '
363 client_view "//depot/... //client/..." &&
364 test_when_finished cleanup_git &&
365 git p4 clone --use-client-spec --dest="$git" //depot/dir1 &&
368 echo git-wild-hash >dir1/git-wild#hash &&
369 if test_have_prereq !MINGW,!CYGWIN
371 echo git-wild-star >dir1/git-wild\*star
373 echo git-wild-at >dir1/git-wild@at &&
374 echo git-wild-percent >dir1/git-wild%percent &&
375 git add dir1/git-wild* &&
376 git commit -m "add some wildcard filenames" &&
377 git config git-p4.skipSubmitEditCheck true &&
382 test_path_is_file dir1/git-wild#hash &&
383 if test_have_prereq !MINGW,!CYGWIN
385 test_path_is_file dir1/git-wild\*star
387 test_path_is_file dir1/git-wild@at &&
388 test_path_is_file dir1/git-wild%percent
391 # delete these carefully, cannot just do "p4 delete"
392 # on files with wildcards; but git-p4 knows how
394 git rm dir1/git-wild* &&
395 git commit -m "clean up the wildcards" &&
400 test_expect_success
'reinit depot' '
405 p4 submit -d "delete all files" &&
411 # What happens when two files of the same name are overlaid together?
412 # The last-listed file should take preference.
424 test_expect_success
'overlay collision setup' '
425 client_view "//depot/... //client/..." &&
429 echo dir1/filecollide >dir1/filecollide &&
430 p4 add dir1/filecollide &&
431 p4 submit -d dir1/filecollide &&
432 echo dir2/filecollide >dir2/filecollide &&
433 p4 add dir2/filecollide &&
434 p4 submit -d dir2/filecollide
438 test_expect_success
'overlay collision 1 to 2' '
439 client_view "//depot/dir1/... //client/..." \
440 "+//depot/dir2/... //client/..." &&
441 files="file11 file12 file21 file22 filecollide" &&
442 echo dir2/filecollide >actual &&
443 client_verify $files &&
444 test_cmp actual "$cli"/filecollide &&
445 test_when_finished cleanup_git &&
446 git p4 clone --use-client-spec --dest="$git" //depot &&
448 test_cmp actual "$git"/filecollide
451 test_expect_failure
'overlay collision 2 to 1' '
452 client_view "//depot/dir2/... //client/..." \
453 "+//depot/dir1/... //client/..." &&
454 files="file11 file12 file21 file22 filecollide" &&
455 echo dir1/filecollide >actual &&
456 client_verify $files &&
457 test_cmp actual "$cli"/filecollide &&
458 test_when_finished cleanup_git &&
459 git p4 clone --use-client-spec --dest="$git" //depot &&
461 test_cmp actual "$git"/filecollide
464 test_expect_success
'overlay collision delete 2' '
465 client_view "//depot/... //client/..." &&
469 p4 delete dir2/filecollide &&
470 p4 submit -d "remove dir2/filecollide"
474 # no filecollide, got deleted with dir2
475 test_expect_failure
'overlay collision 1 to 2, but 2 deleted' '
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 update 1' '
486 client_view "//depot/dir1/... //client/dir1/..." &&
490 p4 open dir1/filecollide &&
491 echo dir1/filecollide update >dir1/filecollide &&
492 p4 submit -d "update dir1/filecollide"
496 # still no filecollide, dir2 still wins with the deletion even though the
497 # change to dir1 is more recent
498 test_expect_failure
'overlay collision 1 to 2, but 2 deleted, then 1 updated' '
499 client_view "//depot/dir1/... //client/..." \
500 "+//depot/dir2/... //client/..." &&
501 files="file11 file12 file21 file22" &&
502 client_verify $files &&
503 test_when_finished cleanup_git &&
504 git p4 clone --use-client-spec --dest="$git" //depot &&
508 test_expect_success
'overlay collision delete filecollides' '
509 client_view "//depot/... //client/..." &&
513 p4 delete dir1/filecollide dir2/filecollide &&
514 p4 submit -d "remove filecollides"
519 # Overlays as part of sync, rather than initial checkout:
520 # 1. add a file in dir1
521 # 2. sync to include it
522 # 3. add same file in dir2
523 # 4. sync, make sure content switches as dir2 has priority
524 # 5. add another file in dir1
526 # 7. add/delete same file in dir2
527 # 8. sync, make sure it disappears, again dir2 wins
542 test_expect_success
'overlay sync: add colA in dir1' '
543 client_view "//depot/dir1/... //client/dir1/..." &&
547 echo dir1/colA >dir1/colA &&
549 p4 submit -d dir1/colA
553 test_expect_success
'overlay sync: initial git checkout' '
554 client_view "//depot/dir1/... //client/..." \
555 "+//depot/dir2/... //client/..." &&
556 files="file11 file12 file21 file22 colA" &&
557 echo dir1/colA >actual &&
558 client_verify $files &&
559 test_cmp actual "$cli"/colA &&
560 git p4 clone --use-client-spec --dest="$git" //depot &&
562 test_cmp actual "$git"/colA
565 test_expect_success
'overlay sync: add colA in dir2' '
566 client_view "//depot/dir2/... //client/dir2/..." &&
570 echo dir2/colA >dir2/colA &&
572 p4 submit -d dir2/colA
576 test_expect_success
'overlay sync: colA content switch' '
577 client_view "//depot/dir1/... //client/..." \
578 "+//depot/dir2/... //client/..." &&
579 files="file11 file12 file21 file22 colA" &&
580 echo dir2/colA >actual &&
581 client_verify $files &&
582 test_cmp actual "$cli"/colA &&
585 git p4 sync --use-client-spec &&
586 git merge --ff-only p4/master
589 test_cmp actual "$git"/colA
592 test_expect_success
'overlay sync: add colB in dir1' '
593 client_view "//depot/dir1/... //client/dir1/..." &&
597 echo dir1/colB >dir1/colB &&
599 p4 submit -d dir1/colB
603 test_expect_success
'overlay sync: colB appears' '
604 client_view "//depot/dir1/... //client/..." \
605 "+//depot/dir2/... //client/..." &&
606 files="file11 file12 file21 file22 colA colB" &&
607 echo dir1/colB >actual &&
608 client_verify $files &&
609 test_cmp actual "$cli"/colB &&
612 git p4 sync --use-client-spec &&
613 git merge --ff-only p4/master
616 test_cmp actual "$git"/colB
619 test_expect_success
'overlay sync: add/delete colB in dir2' '
620 client_view "//depot/dir2/... //client/dir2/..." &&
624 echo dir2/colB >dir2/colB &&
626 p4 submit -d dir2/colB &&
627 p4 delete dir2/colB &&
628 p4 submit -d "delete dir2/colB"
632 test_expect_success
'overlay sync: colB disappears' '
633 client_view "//depot/dir1/... //client/..." \
634 "+//depot/dir2/... //client/..." &&
635 files="file11 file12 file21 file22 colA" &&
636 client_verify $files &&
637 test_when_finished cleanup_git &&
640 git p4 sync --use-client-spec &&
641 git merge --ff-only p4/master
646 test_expect_success
'overlay sync: cleanup' '
647 client_view "//depot/... //client/..." &&
651 p4 delete dir1/colA dir2/colA dir1/colB &&
652 p4 submit -d "remove overlay sync files"
657 # Overlay tests again, but swapped so dir1 has priority.
658 # 1. add a file in dir1
659 # 2. sync to include it
660 # 3. add same file in dir2
661 # 4. sync, make sure content does not switch
662 # 5. add another file in dir1
664 # 7. add/delete same file in dir2
665 # 8. sync, make sure it is still there
680 test_expect_success
'overlay sync swap: add colA in dir1' '
681 client_view "//depot/dir1/... //client/dir1/..." &&
685 echo dir1/colA >dir1/colA &&
687 p4 submit -d dir1/colA
691 test_expect_success
'overlay sync swap: initial git checkout' '
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 &&
698 git p4 clone --use-client-spec --dest="$git" //depot &&
700 test_cmp actual "$git"/colA
703 test_expect_success
'overlay sync swap: add colA in dir2' '
704 client_view "//depot/dir2/... //client/dir2/..." &&
708 echo dir2/colA >dir2/colA &&
710 p4 submit -d dir2/colA
714 test_expect_failure
'overlay sync swap: colA no content switch' '
715 client_view "//depot/dir2/... //client/..." \
716 "+//depot/dir1/... //client/..." &&
717 files="file11 file12 file21 file22 colA" &&
718 echo dir1/colA >actual &&
719 client_verify $files &&
720 test_cmp actual "$cli"/colA &&
723 git p4 sync --use-client-spec &&
724 git merge --ff-only p4/master
727 test_cmp actual "$git"/colA
730 test_expect_success
'overlay sync swap: add colB in dir1' '
731 client_view "//depot/dir1/... //client/dir1/..." &&
735 echo dir1/colB >dir1/colB &&
737 p4 submit -d dir1/colB
741 test_expect_success
'overlay sync swap: colB appears' '
742 client_view "//depot/dir2/... //client/..." \
743 "+//depot/dir1/... //client/..." &&
744 files="file11 file12 file21 file22 colA colB" &&
745 echo dir1/colB >actual &&
746 client_verify $files &&
747 test_cmp actual "$cli"/colB &&
750 git p4 sync --use-client-spec &&
751 git merge --ff-only p4/master
754 test_cmp actual "$git"/colB
757 test_expect_success
'overlay sync swap: add/delete colB in dir2' '
758 client_view "//depot/dir2/... //client/dir2/..." &&
762 echo dir2/colB >dir2/colB &&
764 p4 submit -d dir2/colB &&
765 p4 delete dir2/colB &&
766 p4 submit -d "delete dir2/colB"
770 test_expect_failure
'overlay sync swap: colB no change' '
771 client_view "//depot/dir2/... //client/..." \
772 "+//depot/dir1/... //client/..." &&
773 files="file11 file12 file21 file22 colA colB" &&
774 echo dir1/colB >actual &&
775 client_verify $files &&
776 test_cmp actual "$cli"/colB &&
777 test_when_finished cleanup_git &&
780 git p4 sync --use-client-spec &&
781 git merge --ff-only p4/master
784 test_cmp actual "$cli"/colB
787 test_expect_success
'overlay sync swap: cleanup' '
788 client_view "//depot/... //client/..." &&
792 p4 delete dir1/colA dir2/colA dir1/colB &&
793 p4 submit -d "remove overlay sync files"
798 # Rename directories to test quoting in depot-side mappings
807 test_expect_success
'rename files to introduce spaces' '
808 client_view "//depot/... //client/..." &&
809 client_verify dir1/file11 dir1/file12 \
810 dir2/file21 dir2/file22 &&
814 p4 move dir1/... "dir 1"/... &&
816 p4 move dir2/... "dir 2"/... &&
817 p4 submit -d "rename with spaces"
819 client_verify "dir 1/file11" "dir 1/file12" \
820 "dir 2/file21" "dir 2/file22"
823 test_expect_success
'quotes on lhs only' '
824 client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
825 files="cdir1/file11 cdir1/file12" &&
826 client_verify $files &&
827 test_when_finished cleanup_git &&
828 git p4 clone --use-client-spec --dest="$git" //depot &&
832 test_expect_success
'quotes on both sides' '
833 client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
834 client_verify "cdir 1/file11" "cdir 1/file12" &&
835 test_when_finished cleanup_git &&
836 git p4 clone --use-client-spec --dest="$git" //depot &&
837 git_verify "cdir 1/file11" "cdir 1/file12"