3 test_description
='git p4 tests for p4 branches'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'start p4d' '
18 # 3: integrate //depot/main/... -> //depot/branch1/...
20 # 5: //depot/branch1/f5
21 # .: named branch branch2
22 # 6: integrate -b branch2
23 # 7: //depot/branch2/f7
26 test_expect_success
'basic p4 branches' '
33 p4 submit -d "main/f1" &&
37 p4 submit -d "main/f2" &&
39 p4 integrate //depot/main/... //depot/branch1/... &&
40 p4 submit -d "integrate main to branch1" &&
44 p4 submit -d "main/f4" &&
46 echo f5 >branch1/f5 &&
48 p4 submit -d "branch1/f5" &&
50 p4 branch -i <<-EOF &&
52 View: //depot/main/... //depot/branch2/...
55 p4 integrate -b branch2 &&
56 p4 submit -d "integrate main to branch2" &&
58 echo f7 >branch2/f7 &&
60 p4 submit -d "branch2/f7" &&
64 p4 submit -d "main/f8"
68 test_expect_success
'import main, no branch detection' '
69 test_when_finished cleanup_git &&
70 git p4 clone --dest="$git" //depot/main@all &&
73 git log --oneline --graph --decorate --all &&
74 git rev-list main -- >wc &&
75 test_line_count = 4 wc
79 test_expect_success
'import branch1, no branch detection' '
80 test_when_finished cleanup_git &&
81 git p4 clone --dest="$git" //depot/branch1@all &&
84 git log --oneline --graph --decorate --all &&
85 git rev-list main -- >wc &&
86 test_line_count = 2 wc
90 test_expect_success
'import branch2, no branch detection' '
91 test_when_finished cleanup_git &&
92 git p4 clone --dest="$git" //depot/branch2@all &&
95 git log --oneline --graph --decorate --all &&
96 git rev-list main -- >wc &&
97 test_line_count = 2 wc
101 test_expect_success
'import depot, no branch detection' '
102 test_when_finished cleanup_git &&
103 git p4 clone --dest="$git" //depot@all &&
106 git log --oneline --graph --decorate --all &&
107 git rev-list main -- >wc &&
108 test_line_count = 8 wc
112 test_expect_success
'import depot, branch detection' '
113 test_when_finished cleanup_git &&
114 git p4 clone --dest="$git" --detect-branches //depot@all &&
118 git log --oneline --graph --decorate --all &&
121 git rev-list main -- >wc &&
122 test_line_count = 4 wc &&
124 # 3 main, 1 integrate, 1 on branch2
125 git rev-list p4/depot/branch2 >wc &&
126 test_line_count = 5 wc &&
128 # no branch1, since no p4 branch created for it
129 test_must_fail git show-ref p4/depot/branch1
133 test_expect_success
'sync specific detected branch' '
134 test_when_finished cleanup_git &&
135 git p4 clone --dest="$git" --detect-branches //depot@all &&
138 git p4 sync --branch=depot/branch2 >out &&
139 test_grep "No changes to import!" out
143 test_expect_success
'import depot, branch detection, branchList branch definition' '
144 test_when_finished cleanup_git &&
145 test_create_repo "$git" &&
148 git config git-p4.branchList main:branch1 &&
149 git p4 clone --dest=. --detect-branches //depot@all &&
151 git log --oneline --graph --decorate --all &&
154 git rev-list main -- >wc &&
155 test_line_count = 4 wc &&
157 # 3 main, 1 integrate, 1 on branch2
158 git rev-list p4/depot/branch2 >wc &&
159 test_line_count = 5 wc &&
161 # 2 main, 1 integrate, 1 on branch1
162 git rev-list p4/depot/branch1 >wc &&
163 test_line_count = 4 wc
167 test_expect_success
'restart p4d' '
168 stop_and_cleanup_p4d &&
173 # 1: //depot/branch1/file1
174 # //depot/branch1/file2
175 # 2: integrate //depot/branch1/... -> //depot/branch2/...
176 # 3: //depot/branch1/file3
177 # 4: //depot/branch1/file2 (edit)
178 # 5: integrate //depot/branch1/... -> //depot/branch3/...
180 ## Create a simple branch structure in P4 depot.
181 test_expect_success
'add simple p4 branches' '
188 p4 add file1 file2 &&
189 p4 submit -d "Create branch1" &&
190 p4 integrate //depot/branch1/... //depot/branch2/... &&
191 p4 submit -d "Integrate branch2 from branch1" &&
194 p4 submit -d "add file3 in branch1" &&
196 echo update >>file2 &&
197 p4 submit -d "update file2 in branch1" &&
198 p4 integrate //depot/branch1/... //depot/branch3/... &&
199 p4 submit -d "Integrate branch3 from branch1"
203 # Configure branches through git-config and clone them.
204 # All files are tested to make sure branches were cloned correctly.
205 # Finally, make an update to branch1 on P4 side to check if it is imported
206 # correctly by git p4.
207 test_expect_success
'git p4 clone simple branches' '
208 test_when_finished cleanup_git &&
209 test_create_repo "$git" &&
212 git config git-p4.branchList branch1:branch2 &&
213 git config --add git-p4.branchList branch1:branch3 &&
214 git p4 clone --dest=. --detect-branches //depot@all &&
215 git log --all --graph --decorate --stat &&
216 git reset --hard p4/depot/branch1 &&
217 test_path_is_file file1 &&
218 test_path_is_file file2 &&
219 test_path_is_file file3 &&
221 git reset --hard p4/depot/branch2 &&
222 test_path_is_file file1 &&
223 test_path_is_file file2 &&
225 ! grep update file2 &&
226 git reset --hard p4/depot/branch3 &&
227 test_path_is_file file1 &&
228 test_path_is_file file2 &&
229 test_path_is_file file3 &&
234 echo file2_ >>file2 &&
235 p4 submit -d "update file2 in branch1" &&
237 git reset --hard p4/depot/branch1 &&
243 # Create a complex branch structure in P4 depot to check if they are correctly
244 # cloned. The branches are created from older changelists to check if git p4 is
245 # able to correctly detect them.
246 # The final expected structure is:
249 # | `- file2 (updated)
256 # | `- file2 (updated)
265 test_expect_success
'git p4 add complex branches' '
268 changelist=$(p4 changes -m1 //depot/... | cut -d" " -f2) &&
269 changelist=$(($changelist - 5)) &&
270 p4 integrate //depot/branch1/...@$changelist //depot/branch4/... &&
271 p4 submit -d "Integrate branch4 from branch1@${changelist}" &&
272 changelist=$(($changelist + 2)) &&
273 p4 integrate //depot/branch1/...@$changelist //depot/branch5/... &&
274 p4 submit -d "Integrate branch5 from branch1@${changelist}"
278 # Configure branches through git-config and clone them. git p4 will only be able
279 # to clone the original structure if it is able to detect the origin changelist
281 test_expect_success
'git p4 clone complex branches' '
282 test_when_finished cleanup_git &&
283 test_create_repo "$git" &&
286 git config git-p4.branchList branch1:branch2 &&
287 git config --add git-p4.branchList branch1:branch3 &&
288 git config --add git-p4.branchList branch1:branch4 &&
289 git config --add git-p4.branchList branch1:branch5 &&
290 git p4 clone --dest=. --detect-branches //depot@all &&
291 git log --all --graph --decorate --stat &&
292 git reset --hard p4/depot/branch1 &&
293 test_path_is_file file1 &&
294 test_path_is_file file2 &&
295 test_path_is_file file3 &&
297 git reset --hard p4/depot/branch2 &&
298 test_path_is_file file1 &&
299 test_path_is_file file2 &&
300 test_path_is_missing file3 &&
301 ! grep update file2 &&
302 git reset --hard p4/depot/branch3 &&
303 test_path_is_file file1 &&
304 test_path_is_file file2 &&
305 test_path_is_file file3 &&
307 git reset --hard p4/depot/branch4 &&
308 git diff-tree --quiet HEAD &&
309 test_path_is_file file1 &&
310 test_path_is_file file2 &&
311 test_path_is_missing file3 &&
312 ! grep update file2 &&
313 git reset --hard p4/depot/branch5 &&
314 git diff-tree --quiet HEAD &&
315 test_path_is_file file1 &&
316 test_path_is_file file2 &&
317 test_path_is_file file3 &&
318 ! grep update file2 &&
319 test_must_fail git show-ref --verify refs/git-p4-tmp
323 # Move branch3/file3 to branch4/file3 in a single changelist
324 test_expect_success
'git p4 submit to two branches in a single changelist' '
327 p4 integrate //depot/branch3/file3 //depot/branch4/file3 &&
328 p4 delete //depot/branch3/file3 &&
329 p4 submit -d "Move branch3/file3 to branch4/file3"
333 # Confirm that changes to two branches done in a single changelist
334 # are correctly imported by git p4
335 test_expect_success
'git p4 sync changes to two branches in the same changelist' '
336 test_when_finished cleanup_git &&
337 test_create_repo "$git" &&
340 git config git-p4.branchList branch1:branch2 &&
341 git config --add git-p4.branchList branch1:branch3 &&
342 git config --add git-p4.branchList branch1:branch4 &&
343 git config --add git-p4.branchList branch1:branch5 &&
344 git p4 clone --dest=. --detect-branches //depot@all &&
345 git log --all --graph --decorate --stat &&
346 git reset --hard p4/depot/branch1 &&
347 test_path_is_file file1 &&
348 test_path_is_file file2 &&
349 test_path_is_file file3 &&
351 git reset --hard p4/depot/branch2 &&
352 test_path_is_file file1 &&
353 test_path_is_file file2 &&
354 test_path_is_missing file3 &&
355 ! grep update file2 &&
356 git reset --hard p4/depot/branch3 &&
357 test_path_is_file file1 &&
358 test_path_is_file file2 &&
359 test_path_is_missing file3 &&
361 git reset --hard p4/depot/branch4 &&
362 test_path_is_file file1 &&
363 test_path_is_file file2 &&
364 test_path_is_file file3 &&
365 ! grep update file2 &&
366 git reset --hard p4/depot/branch5 &&
367 test_path_is_file file1 &&
368 test_path_is_file file2 &&
369 test_path_is_file file3 &&
370 ! grep update file2 &&
371 test_must_fail git show-ref --verify refs/git-p4-tmp
375 # Create a branch by integrating a single file
376 test_expect_success
'git p4 file subset branch' '
379 p4 integrate //depot/branch1/file1 //depot/branch6/file1 &&
380 p4 submit -d "Integrate file1 alone from branch1 to branch6"
384 # Check if git p4 creates a new branch containing a single file,
385 # instead of keeping the old files from the original branch
386 test_expect_failure
'git p4 clone file subset branch' '
387 test_when_finished cleanup_git &&
388 test_create_repo "$git" &&
391 git config git-p4.branchList branch1:branch2 &&
392 git config --add git-p4.branchList branch1:branch3 &&
393 git config --add git-p4.branchList branch1:branch4 &&
394 git config --add git-p4.branchList branch1:branch5 &&
395 git config --add git-p4.branchList branch1:branch6 &&
396 git p4 clone --dest=. --detect-branches //depot@all &&
397 git log --all --graph --decorate --stat &&
398 git reset --hard p4/depot/branch1 &&
399 test_path_is_file file1 &&
400 test_path_is_file file2 &&
401 test_path_is_file file3 &&
403 git reset --hard p4/depot/branch2 &&
404 test_path_is_file file1 &&
405 test_path_is_file file2 &&
406 test_path_is_missing file3 &&
407 ! grep update file2 &&
408 git reset --hard p4/depot/branch3 &&
409 test_path_is_file file1 &&
410 test_path_is_file file2 &&
411 test_path_is_missing file3 &&
413 git reset --hard p4/depot/branch4 &&
414 test_path_is_file file1 &&
415 test_path_is_file file2 &&
416 test_path_is_file file3 &&
417 ! grep update file2 &&
418 git reset --hard p4/depot/branch5 &&
419 test_path_is_file file1 &&
420 test_path_is_file file2 &&
421 test_path_is_file file3 &&
422 ! grep update file2 &&
423 git reset --hard p4/depot/branch6 &&
424 test_path_is_file file1 &&
425 test_path_is_missing file2 &&
426 test_path_is_missing file3
430 # Check that excluded files are omitted during import
431 test_expect_success
'git p4 clone complex branches with excluded files' '
432 test_when_finished cleanup_git &&
433 test_create_repo "$git" &&
436 git config git-p4.branchList branch1:branch2 &&
437 git config --add git-p4.branchList branch1:branch3 &&
438 git config --add git-p4.branchList branch1:branch4 &&
439 git config --add git-p4.branchList branch1:branch5 &&
440 git config --add git-p4.branchList branch1:branch6 &&
441 git p4 clone --dest=. --detect-branches -//depot/branch1/file2 -//depot/branch2/file2 -//depot/branch3/file2 -//depot/branch4/file2 -//depot/branch5/file2 -//depot/branch6/file2 //depot@all &&
442 git log --all --graph --decorate --stat &&
443 git reset --hard p4/depot/branch1 &&
444 test_path_is_file file1 &&
445 test_path_is_missing file2 &&
446 test_path_is_file file3 &&
447 git reset --hard p4/depot/branch2 &&
448 test_path_is_file file1 &&
449 test_path_is_missing file2 &&
450 test_path_is_missing file3 &&
451 git reset --hard p4/depot/branch3 &&
452 test_path_is_file file1 &&
453 test_path_is_missing file2 &&
454 test_path_is_missing file3 &&
455 git reset --hard p4/depot/branch4 &&
456 test_path_is_file file1 &&
457 test_path_is_missing file2 &&
458 test_path_is_file file3 &&
459 git reset --hard p4/depot/branch5 &&
460 test_path_is_file file1 &&
461 test_path_is_missing file2 &&
462 test_path_is_file file3 &&
463 git reset --hard p4/depot/branch6 &&
464 test_path_is_file file1 &&
465 test_path_is_missing file2 &&
466 test_path_is_missing file3
470 # From a report in https://stackoverflow.com/questions/11893688
471 # where --use-client-spec caused branch prefixes not to be removed;
472 # every file in git appeared into a subdirectory of the branch name.
473 test_expect_success
'use-client-spec detect-branches setup' '
478 client_view "//depot/usecs/... //client/..." &&
480 echo b1/b1-file1 >b1/b1-file1 &&
481 p4 add b1/b1-file1 &&
482 p4 submit -d "b1/b1-file1" &&
484 p4 integrate //depot/usecs/b1/... //depot/usecs/b2/... &&
485 p4 submit -d "b1 -> b2" &&
486 p4 branch -i <<-EOF &&
488 View: //depot/usecs/b1/... //depot/usecs/b2/...
491 echo b2/b2-file2 >b2/b2-file2 &&
492 p4 add b2/b2-file2 &&
493 p4 submit -d "b2/b2-file2"
497 test_expect_success
'use-client-spec detect-branches files in top-level' '
498 test_when_finished cleanup_git &&
499 test_create_repo "$git" &&
502 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
503 git checkout -b main p4/usecs/b1 &&
504 test_path_is_file b1-file1 &&
505 test_path_is_missing b2-file2 &&
506 test_path_is_missing b1 &&
507 test_path_is_missing b2 &&
509 git checkout -b b2 p4/usecs/b2 &&
510 test_path_is_file b1-file1 &&
511 test_path_is_file b2-file2 &&
512 test_path_is_missing b1 &&
513 test_path_is_missing b2
517 test_expect_success
'use-client-spec detect-branches skips branches setup' '
521 p4 integrate //depot/usecs/b1/... //depot/usecs/b3/... &&
522 p4 submit -d "b1 -> b3" &&
523 p4 branch -i <<-EOF &&
525 View: //depot/usecs/b1/... //depot/usecs/b3/...
528 echo b3/b3-file3_1 >b3/b3-file3_1 &&
529 echo b3/b3-file3_2 >b3/b3-file3_2 &&
530 p4 add b3/b3-file3_1 &&
531 p4 add b3/b3-file3_2 &&
532 p4 submit -d "b3/b3-file3_1 b3/b3-file3_2"
536 test_expect_success
'use-client-spec detect-branches skips branches' '
537 client_view "//depot/usecs/... //client/..." \
538 "-//depot/usecs/b3/... //client/b3/..." &&
539 test_when_finished cleanup_git &&
540 test_create_repo "$git" &&
543 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
544 test_must_fail git rev-parse refs/remotes/p4/usecs/b3
548 test_expect_success
'use-client-spec detect-branches skips files in branches' '
549 client_view "//depot/usecs/... //client/..." \
550 "-//depot/usecs/b3/b3-file3_1 //client/b3/b3-file3_1" &&
551 test_when_finished cleanup_git &&
552 test_create_repo "$git" &&
555 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
556 git checkout -b main p4/usecs/b3 &&
557 test_path_is_file b1-file1 &&
558 test_path_is_file b3-file3_2 &&
559 test_path_is_missing b3-file3_1
563 test_expect_success
'restart p4d' '
564 stop_and_cleanup_p4d &&
569 # 1: //depot/branch1/base/file1
570 # //depot/branch1/base/file2
571 # //depot/branch1/base/dir/sub_file1
572 # 2: integrate //depot/branch1/base/... -> //depot/branch2/base/...
573 # 3: //depot/branch1/base/file3
574 # 4: //depot/branch1/base/file2 (edit)
575 # 5: integrate //depot/branch1/base/... -> //depot/branch3/base/...
577 # Note: the client view removes the "base" folder from the workspace
578 # and moves sub_file1 one level up.
579 test_expect_success
'add simple p4 branches with common base folder on each branch' '
582 client_view "//depot/branch1/base/... //client/branch1/..." \
583 "//depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1" \
584 "//depot/branch2/base/... //client/branch2/..." \
585 "//depot/branch3/base/... //client/branch3/..." &&
591 echo sub_file1 >sub_file1 &&
592 p4 add file1 file2 sub_file1 &&
593 p4 submit -d "Create branch1" &&
594 p4 integrate //depot/branch1/base/... //depot/branch2/base/... &&
595 p4 submit -d "Integrate branch2 from branch1" &&
598 p4 submit -d "add file3 in branch1" &&
600 echo update >>file2 &&
601 p4 submit -d "update file2 in branch1" &&
602 p4 integrate //depot/branch1/base/... //depot/branch3/base/... &&
603 p4 submit -d "Integrate branch3 from branch1"
607 # Configure branches through git-config and clone them.
608 # All files are tested to make sure branches were cloned correctly.
609 # Finally, make an update to branch1 on P4 side to check if it is imported
610 # correctly by git p4.
611 # git p4 is expected to use the client view to also not include the common
612 # "base" folder in the imported directory structure.
613 test_expect_success
'git p4 clone simple branches with base folder on server side' '
614 test_create_repo "$git" &&
617 git config git-p4.branchList branch1:branch2 &&
618 git config --add git-p4.branchList branch1:branch3 &&
619 git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
620 git log --all --graph --decorate --stat &&
621 git reset --hard p4/depot/branch1 &&
622 test_path_is_file file1 &&
623 test_path_is_file file2 &&
624 test_path_is_file file3 &&
625 test_path_is_file sub_file1 &&
627 git reset --hard p4/depot/branch2 &&
628 test_path_is_file file1 &&
629 test_path_is_file file2 &&
631 test_path_is_file sub_file1 &&
632 ! grep update file2 &&
633 git reset --hard p4/depot/branch3 &&
634 test_path_is_file file1 &&
635 test_path_is_file file2 &&
636 test_path_is_file file3 &&
637 test_path_is_file sub_file1 &&
642 echo file2_ >>file2 &&
643 p4 submit -d "update file2 in branch1" &&
645 git reset --hard p4/depot/branch1 &&
651 # Now update a file in one of the branches in git and submit to P4
652 test_expect_success
'Update a file in git side and submit to P4 using client view' '
653 test_when_finished cleanup_git &&
656 git reset --hard p4/depot/branch1 &&
657 echo "client spec" >> file1 &&
659 git commit -m "update file1 in branch1" &&
660 git config git-p4.skipSubmitEdit true &&
661 git p4 submit --verbose &&
665 grep "client spec" file1
669 test_expect_success
'restart p4d (case folding enabled)' '
670 stop_and_cleanup_p4d &&
675 # 1: //depot/main/mf1
676 # 2: integrate //depot/main/... -> //depot/branch1/...
677 # 3: //depot/main/mf2
678 # 4: //depot/BRANCH1/B1f3
679 # 5: //depot/branch1/b1f4
681 test_expect_success
!CASE_INSENSITIVE_FS
'basic p4 branches for case folding' '
686 echo mf1 >main/mf1 &&
688 p4 submit -d "main/mf1" &&
690 p4 integrate //depot/main/... //depot/branch1/... &&
691 p4 submit -d "integrate main to branch1" &&
693 echo mf2 >main/mf2 &&
695 p4 submit -d "main/mf2" &&
698 echo B1f3 >BRANCH1/B1f3 &&
699 p4 add BRANCH1/B1f3 &&
700 p4 submit -d "BRANCH1/B1f3" &&
702 echo b1f4 >branch1/b1f4 &&
703 p4 add branch1/b1f4 &&
704 p4 submit -d "branch1/b1f4"
708 # Check that files are properly split across branches when ignorecase is set
709 test_expect_success
!CASE_INSENSITIVE_FS
'git p4 clone, branchList branch definition, ignorecase' '
710 test_when_finished cleanup_git &&
711 test_create_repo "$git" &&
714 git config git-p4.branchList main:branch1 &&
715 git config --type=bool core.ignoreCase true &&
716 git p4 clone --dest=. --detect-branches //depot@all &&
718 git log --all --graph --decorate --stat &&
720 git reset --hard p4/master &&
721 test_path_is_file mf1 &&
722 test_path_is_file mf2 &&
723 test_path_is_missing B1f3 &&
724 test_path_is_missing b1f4 &&
726 git reset --hard p4/depot/branch1 &&
727 test_path_is_file mf1 &&
728 test_path_is_missing mf2 &&
729 test_path_is_file B1f3 &&
730 test_path_is_file b1f4
734 # Check that files are properly split across branches when ignorecase is set, use-client-spec case
735 test_expect_success
!CASE_INSENSITIVE_FS
'git p4 clone with client-spec, branchList branch definition, ignorecase' '
736 client_view "//depot/... //client/..." &&
737 test_when_finished cleanup_git &&
738 test_create_repo "$git" &&
741 git config git-p4.branchList main:branch1 &&
742 git config --type=bool core.ignoreCase true &&
743 git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
745 git log --all --graph --decorate --stat &&
747 git reset --hard p4/master &&
748 test_path_is_file mf1 &&
749 test_path_is_file mf2 &&
750 test_path_is_missing B1f3 &&
751 test_path_is_missing b1f4 &&
753 git reset --hard p4/depot/branch1 &&
754 test_path_is_file mf1 &&
755 test_path_is_missing mf2 &&
756 test_path_is_file B1f3 &&
757 test_path_is_file b1f4