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
10 test_expect_success
'start p4d' '
17 # 3: integrate //depot/main/... -> //depot/branch1/...
19 # 5: //depot/branch1/f5
20 # .: named branch branch2
21 # 6: integrate -b branch2
22 # 7: //depot/branch2/f7
25 test_expect_success
'basic p4 branches' '
32 p4 submit -d "main/f1" &&
36 p4 submit -d "main/f2" &&
38 p4 integrate //depot/main/... //depot/branch1/... &&
39 p4 submit -d "integrate main to branch1" &&
43 p4 submit -d "main/f4" &&
45 echo f5 >branch1/f5 &&
47 p4 submit -d "branch1/f5" &&
49 p4 branch -i <<-EOF &&
51 View: //depot/main/... //depot/branch2/...
54 p4 integrate -b branch2 &&
55 p4 submit -d "integrate main to branch2" &&
57 echo f7 >branch2/f7 &&
59 p4 submit -d "branch2/f7" &&
63 p4 submit -d "main/f8"
67 test_expect_success
'import main, no branch detection' '
68 test_when_finished cleanup_git &&
69 git p4 clone --dest="$git" //depot/main@all &&
72 git log --oneline --graph --decorate --all &&
73 git rev-list main -- >wc &&
74 test_line_count = 4 wc
78 test_expect_success
'import branch1, no branch detection' '
79 test_when_finished cleanup_git &&
80 git p4 clone --dest="$git" //depot/branch1@all &&
83 git log --oneline --graph --decorate --all &&
84 git rev-list main -- >wc &&
85 test_line_count = 2 wc
89 test_expect_success
'import branch2, no branch detection' '
90 test_when_finished cleanup_git &&
91 git p4 clone --dest="$git" //depot/branch2@all &&
94 git log --oneline --graph --decorate --all &&
95 git rev-list main -- >wc &&
96 test_line_count = 2 wc
100 test_expect_success
'import depot, no branch detection' '
101 test_when_finished cleanup_git &&
102 git p4 clone --dest="$git" //depot@all &&
105 git log --oneline --graph --decorate --all &&
106 git rev-list main -- >wc &&
107 test_line_count = 8 wc
111 test_expect_success
'import depot, branch detection' '
112 test_when_finished cleanup_git &&
113 git p4 clone --dest="$git" --detect-branches //depot@all &&
117 git log --oneline --graph --decorate --all &&
120 git rev-list main -- >wc &&
121 test_line_count = 4 wc &&
123 # 3 main, 1 integrate, 1 on branch2
124 git rev-list p4/depot/branch2 >wc &&
125 test_line_count = 5 wc &&
127 # no branch1, since no p4 branch created for it
128 test_must_fail git show-ref p4/depot/branch1
132 test_expect_success
'sync specific detected branch' '
133 test_when_finished cleanup_git &&
134 git p4 clone --dest="$git" --detect-branches //depot@all &&
137 git p4 sync --branch=depot/branch2 >out &&
138 test_grep "No changes to import!" out
142 test_expect_success
'import depot, branch detection, branchList branch definition' '
143 test_when_finished cleanup_git &&
144 test_create_repo "$git" &&
147 git config git-p4.branchList main:branch1 &&
148 git p4 clone --dest=. --detect-branches //depot@all &&
150 git log --oneline --graph --decorate --all &&
153 git rev-list main -- >wc &&
154 test_line_count = 4 wc &&
156 # 3 main, 1 integrate, 1 on branch2
157 git rev-list p4/depot/branch2 >wc &&
158 test_line_count = 5 wc &&
160 # 2 main, 1 integrate, 1 on branch1
161 git rev-list p4/depot/branch1 >wc &&
162 test_line_count = 4 wc
166 test_expect_success
'restart p4d' '
167 stop_and_cleanup_p4d &&
172 # 1: //depot/branch1/file1
173 # //depot/branch1/file2
174 # 2: integrate //depot/branch1/... -> //depot/branch2/...
175 # 3: //depot/branch1/file3
176 # 4: //depot/branch1/file2 (edit)
177 # 5: integrate //depot/branch1/... -> //depot/branch3/...
179 ## Create a simple branch structure in P4 depot.
180 test_expect_success
'add simple p4 branches' '
187 p4 add file1 file2 &&
188 p4 submit -d "Create branch1" &&
189 p4 integrate //depot/branch1/... //depot/branch2/... &&
190 p4 submit -d "Integrate branch2 from branch1" &&
193 p4 submit -d "add file3 in branch1" &&
195 echo update >>file2 &&
196 p4 submit -d "update file2 in branch1" &&
197 p4 integrate //depot/branch1/... //depot/branch3/... &&
198 p4 submit -d "Integrate branch3 from branch1"
202 # Configure branches through git-config and clone them.
203 # All files are tested to make sure branches were cloned correctly.
204 # Finally, make an update to branch1 on P4 side to check if it is imported
205 # correctly by git p4.
206 test_expect_success
'git p4 clone simple branches' '
207 test_when_finished cleanup_git &&
208 test_create_repo "$git" &&
211 git config git-p4.branchList branch1:branch2 &&
212 git config --add git-p4.branchList branch1:branch3 &&
213 git p4 clone --dest=. --detect-branches //depot@all &&
214 git log --all --graph --decorate --stat &&
215 git reset --hard p4/depot/branch1 &&
216 test_path_is_file file1 &&
217 test_path_is_file file2 &&
218 test_path_is_file file3 &&
220 git reset --hard p4/depot/branch2 &&
221 test_path_is_file file1 &&
222 test_path_is_file file2 &&
224 ! grep update file2 &&
225 git reset --hard p4/depot/branch3 &&
226 test_path_is_file file1 &&
227 test_path_is_file file2 &&
228 test_path_is_file file3 &&
233 echo file2_ >>file2 &&
234 p4 submit -d "update file2 in branch1" &&
236 git reset --hard p4/depot/branch1 &&
242 # Create a complex branch structure in P4 depot to check if they are correctly
243 # cloned. The branches are created from older changelists to check if git p4 is
244 # able to correctly detect them.
245 # The final expected structure is:
248 # | `- file2 (updated)
255 # | `- file2 (updated)
264 test_expect_success
'git p4 add complex branches' '
267 changelist=$(p4 changes -m1 //depot/... | cut -d" " -f2) &&
268 changelist=$(($changelist - 5)) &&
269 p4 integrate //depot/branch1/...@$changelist //depot/branch4/... &&
270 p4 submit -d "Integrate branch4 from branch1@${changelist}" &&
271 changelist=$(($changelist + 2)) &&
272 p4 integrate //depot/branch1/...@$changelist //depot/branch5/... &&
273 p4 submit -d "Integrate branch5 from branch1@${changelist}"
277 # Configure branches through git-config and clone them. git p4 will only be able
278 # to clone the original structure if it is able to detect the origin changelist
280 test_expect_success
'git p4 clone complex branches' '
281 test_when_finished cleanup_git &&
282 test_create_repo "$git" &&
285 git config git-p4.branchList branch1:branch2 &&
286 git config --add git-p4.branchList branch1:branch3 &&
287 git config --add git-p4.branchList branch1:branch4 &&
288 git config --add git-p4.branchList branch1:branch5 &&
289 git p4 clone --dest=. --detect-branches //depot@all &&
290 git log --all --graph --decorate --stat &&
291 git reset --hard p4/depot/branch1 &&
292 test_path_is_file file1 &&
293 test_path_is_file file2 &&
294 test_path_is_file file3 &&
296 git reset --hard p4/depot/branch2 &&
297 test_path_is_file file1 &&
298 test_path_is_file file2 &&
299 test_path_is_missing file3 &&
300 ! grep update file2 &&
301 git reset --hard p4/depot/branch3 &&
302 test_path_is_file file1 &&
303 test_path_is_file file2 &&
304 test_path_is_file file3 &&
306 git reset --hard p4/depot/branch4 &&
307 git diff-tree --quiet HEAD &&
308 test_path_is_file file1 &&
309 test_path_is_file file2 &&
310 test_path_is_missing file3 &&
311 ! grep update file2 &&
312 git reset --hard p4/depot/branch5 &&
313 git diff-tree --quiet HEAD &&
314 test_path_is_file file1 &&
315 test_path_is_file file2 &&
316 test_path_is_file file3 &&
317 ! grep update file2 &&
318 test_must_fail git show-ref --verify refs/git-p4-tmp
322 # Move branch3/file3 to branch4/file3 in a single changelist
323 test_expect_success
'git p4 submit to two branches in a single changelist' '
326 p4 integrate //depot/branch3/file3 //depot/branch4/file3 &&
327 p4 delete //depot/branch3/file3 &&
328 p4 submit -d "Move branch3/file3 to branch4/file3"
332 # Confirm that changes to two branches done in a single changelist
333 # are correctly imported by git p4
334 test_expect_success
'git p4 sync changes to two branches in the same changelist' '
335 test_when_finished cleanup_git &&
336 test_create_repo "$git" &&
339 git config git-p4.branchList branch1:branch2 &&
340 git config --add git-p4.branchList branch1:branch3 &&
341 git config --add git-p4.branchList branch1:branch4 &&
342 git config --add git-p4.branchList branch1:branch5 &&
343 git p4 clone --dest=. --detect-branches //depot@all &&
344 git log --all --graph --decorate --stat &&
345 git reset --hard p4/depot/branch1 &&
346 test_path_is_file file1 &&
347 test_path_is_file file2 &&
348 test_path_is_file file3 &&
350 git reset --hard p4/depot/branch2 &&
351 test_path_is_file file1 &&
352 test_path_is_file file2 &&
353 test_path_is_missing file3 &&
354 ! grep update file2 &&
355 git reset --hard p4/depot/branch3 &&
356 test_path_is_file file1 &&
357 test_path_is_file file2 &&
358 test_path_is_missing file3 &&
360 git reset --hard p4/depot/branch4 &&
361 test_path_is_file file1 &&
362 test_path_is_file file2 &&
363 test_path_is_file file3 &&
364 ! grep update file2 &&
365 git reset --hard p4/depot/branch5 &&
366 test_path_is_file file1 &&
367 test_path_is_file file2 &&
368 test_path_is_file file3 &&
369 ! grep update file2 &&
370 test_must_fail git show-ref --verify refs/git-p4-tmp
374 # Create a branch by integrating a single file
375 test_expect_success
'git p4 file subset branch' '
378 p4 integrate //depot/branch1/file1 //depot/branch6/file1 &&
379 p4 submit -d "Integrate file1 alone from branch1 to branch6"
383 # Check if git p4 creates a new branch containing a single file,
384 # instead of keeping the old files from the original branch
385 test_expect_failure
'git p4 clone file subset branch' '
386 test_when_finished cleanup_git &&
387 test_create_repo "$git" &&
390 git config git-p4.branchList branch1:branch2 &&
391 git config --add git-p4.branchList branch1:branch3 &&
392 git config --add git-p4.branchList branch1:branch4 &&
393 git config --add git-p4.branchList branch1:branch5 &&
394 git config --add git-p4.branchList branch1:branch6 &&
395 git p4 clone --dest=. --detect-branches //depot@all &&
396 git log --all --graph --decorate --stat &&
397 git reset --hard p4/depot/branch1 &&
398 test_path_is_file file1 &&
399 test_path_is_file file2 &&
400 test_path_is_file file3 &&
402 git reset --hard p4/depot/branch2 &&
403 test_path_is_file file1 &&
404 test_path_is_file file2 &&
405 test_path_is_missing file3 &&
406 ! grep update file2 &&
407 git reset --hard p4/depot/branch3 &&
408 test_path_is_file file1 &&
409 test_path_is_file file2 &&
410 test_path_is_missing file3 &&
412 git reset --hard p4/depot/branch4 &&
413 test_path_is_file file1 &&
414 test_path_is_file file2 &&
415 test_path_is_file file3 &&
416 ! grep update file2 &&
417 git reset --hard p4/depot/branch5 &&
418 test_path_is_file file1 &&
419 test_path_is_file file2 &&
420 test_path_is_file file3 &&
421 ! grep update file2 &&
422 git reset --hard p4/depot/branch6 &&
423 test_path_is_file file1 &&
424 test_path_is_missing file2 &&
425 test_path_is_missing file3
429 # Check that excluded files are omitted during import
430 test_expect_success
'git p4 clone complex branches with excluded files' '
431 test_when_finished cleanup_git &&
432 test_create_repo "$git" &&
435 git config git-p4.branchList branch1:branch2 &&
436 git config --add git-p4.branchList branch1:branch3 &&
437 git config --add git-p4.branchList branch1:branch4 &&
438 git config --add git-p4.branchList branch1:branch5 &&
439 git config --add git-p4.branchList branch1:branch6 &&
440 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 &&
441 git log --all --graph --decorate --stat &&
442 git reset --hard p4/depot/branch1 &&
443 test_path_is_file file1 &&
444 test_path_is_missing file2 &&
445 test_path_is_file file3 &&
446 git reset --hard p4/depot/branch2 &&
447 test_path_is_file file1 &&
448 test_path_is_missing file2 &&
449 test_path_is_missing file3 &&
450 git reset --hard p4/depot/branch3 &&
451 test_path_is_file file1 &&
452 test_path_is_missing file2 &&
453 test_path_is_missing file3 &&
454 git reset --hard p4/depot/branch4 &&
455 test_path_is_file file1 &&
456 test_path_is_missing file2 &&
457 test_path_is_file file3 &&
458 git reset --hard p4/depot/branch5 &&
459 test_path_is_file file1 &&
460 test_path_is_missing file2 &&
461 test_path_is_file file3 &&
462 git reset --hard p4/depot/branch6 &&
463 test_path_is_file file1 &&
464 test_path_is_missing file2 &&
465 test_path_is_missing file3
469 # From a report in https://stackoverflow.com/questions/11893688
470 # where --use-client-spec caused branch prefixes not to be removed;
471 # every file in git appeared into a subdirectory of the branch name.
472 test_expect_success
'use-client-spec detect-branches setup' '
477 client_view "//depot/usecs/... //client/..." &&
479 echo b1/b1-file1 >b1/b1-file1 &&
480 p4 add b1/b1-file1 &&
481 p4 submit -d "b1/b1-file1" &&
483 p4 integrate //depot/usecs/b1/... //depot/usecs/b2/... &&
484 p4 submit -d "b1 -> b2" &&
485 p4 branch -i <<-EOF &&
487 View: //depot/usecs/b1/... //depot/usecs/b2/...
490 echo b2/b2-file2 >b2/b2-file2 &&
491 p4 add b2/b2-file2 &&
492 p4 submit -d "b2/b2-file2"
496 test_expect_success
'use-client-spec detect-branches files in top-level' '
497 test_when_finished cleanup_git &&
498 test_create_repo "$git" &&
501 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
502 git checkout -b main p4/usecs/b1 &&
503 test_path_is_file b1-file1 &&
504 test_path_is_missing b2-file2 &&
505 test_path_is_missing b1 &&
506 test_path_is_missing b2 &&
508 git checkout -b b2 p4/usecs/b2 &&
509 test_path_is_file b1-file1 &&
510 test_path_is_file b2-file2 &&
511 test_path_is_missing b1 &&
512 test_path_is_missing b2
516 test_expect_success
'use-client-spec detect-branches skips branches setup' '
520 p4 integrate //depot/usecs/b1/... //depot/usecs/b3/... &&
521 p4 submit -d "b1 -> b3" &&
522 p4 branch -i <<-EOF &&
524 View: //depot/usecs/b1/... //depot/usecs/b3/...
527 echo b3/b3-file3_1 >b3/b3-file3_1 &&
528 echo b3/b3-file3_2 >b3/b3-file3_2 &&
529 p4 add b3/b3-file3_1 &&
530 p4 add b3/b3-file3_2 &&
531 p4 submit -d "b3/b3-file3_1 b3/b3-file3_2"
535 test_expect_success
'use-client-spec detect-branches skips branches' '
536 client_view "//depot/usecs/... //client/..." \
537 "-//depot/usecs/b3/... //client/b3/..." &&
538 test_when_finished cleanup_git &&
539 test_create_repo "$git" &&
542 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
543 test_must_fail git rev-parse refs/remotes/p4/usecs/b3
547 test_expect_success
'use-client-spec detect-branches skips files in branches' '
548 client_view "//depot/usecs/... //client/..." \
549 "-//depot/usecs/b3/b3-file3_1 //client/b3/b3-file3_1" &&
550 test_when_finished cleanup_git &&
551 test_create_repo "$git" &&
554 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
555 git checkout -b main p4/usecs/b3 &&
556 test_path_is_file b1-file1 &&
557 test_path_is_file b3-file3_2 &&
558 test_path_is_missing b3-file3_1
562 test_expect_success
'restart p4d' '
563 stop_and_cleanup_p4d &&
568 # 1: //depot/branch1/base/file1
569 # //depot/branch1/base/file2
570 # //depot/branch1/base/dir/sub_file1
571 # 2: integrate //depot/branch1/base/... -> //depot/branch2/base/...
572 # 3: //depot/branch1/base/file3
573 # 4: //depot/branch1/base/file2 (edit)
574 # 5: integrate //depot/branch1/base/... -> //depot/branch3/base/...
576 # Note: the client view removes the "base" folder from the workspace
577 # and moves sub_file1 one level up.
578 test_expect_success
'add simple p4 branches with common base folder on each branch' '
581 client_view "//depot/branch1/base/... //client/branch1/..." \
582 "//depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1" \
583 "//depot/branch2/base/... //client/branch2/..." \
584 "//depot/branch3/base/... //client/branch3/..." &&
590 echo sub_file1 >sub_file1 &&
591 p4 add file1 file2 sub_file1 &&
592 p4 submit -d "Create branch1" &&
593 p4 integrate //depot/branch1/base/... //depot/branch2/base/... &&
594 p4 submit -d "Integrate branch2 from branch1" &&
597 p4 submit -d "add file3 in branch1" &&
599 echo update >>file2 &&
600 p4 submit -d "update file2 in branch1" &&
601 p4 integrate //depot/branch1/base/... //depot/branch3/base/... &&
602 p4 submit -d "Integrate branch3 from branch1"
606 # Configure branches through git-config and clone them.
607 # All files are tested to make sure branches were cloned correctly.
608 # Finally, make an update to branch1 on P4 side to check if it is imported
609 # correctly by git p4.
610 # git p4 is expected to use the client view to also not include the common
611 # "base" folder in the imported directory structure.
612 test_expect_success
'git p4 clone simple branches with base folder on server side' '
613 test_create_repo "$git" &&
616 git config git-p4.branchList branch1:branch2 &&
617 git config --add git-p4.branchList branch1:branch3 &&
618 git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
619 git log --all --graph --decorate --stat &&
620 git reset --hard p4/depot/branch1 &&
621 test_path_is_file file1 &&
622 test_path_is_file file2 &&
623 test_path_is_file file3 &&
624 test_path_is_file sub_file1 &&
626 git reset --hard p4/depot/branch2 &&
627 test_path_is_file file1 &&
628 test_path_is_file file2 &&
630 test_path_is_file sub_file1 &&
631 ! grep update file2 &&
632 git reset --hard p4/depot/branch3 &&
633 test_path_is_file file1 &&
634 test_path_is_file file2 &&
635 test_path_is_file file3 &&
636 test_path_is_file sub_file1 &&
641 echo file2_ >>file2 &&
642 p4 submit -d "update file2 in branch1" &&
644 git reset --hard p4/depot/branch1 &&
650 # Now update a file in one of the branches in git and submit to P4
651 test_expect_success
'Update a file in git side and submit to P4 using client view' '
652 test_when_finished cleanup_git &&
655 git reset --hard p4/depot/branch1 &&
656 echo "client spec" >> file1 &&
658 git commit -m "update file1 in branch1" &&
659 git config git-p4.skipSubmitEdit true &&
660 git p4 submit --verbose &&
664 grep "client spec" file1
668 test_expect_success
'restart p4d (case folding enabled)' '
669 stop_and_cleanup_p4d &&
674 # 1: //depot/main/mf1
675 # 2: integrate //depot/main/... -> //depot/branch1/...
676 # 3: //depot/main/mf2
677 # 4: //depot/BRANCH1/B1f3
678 # 5: //depot/branch1/b1f4
680 test_expect_success
!CASE_INSENSITIVE_FS
'basic p4 branches for case folding' '
685 echo mf1 >main/mf1 &&
687 p4 submit -d "main/mf1" &&
689 p4 integrate //depot/main/... //depot/branch1/... &&
690 p4 submit -d "integrate main to branch1" &&
692 echo mf2 >main/mf2 &&
694 p4 submit -d "main/mf2" &&
697 echo B1f3 >BRANCH1/B1f3 &&
698 p4 add BRANCH1/B1f3 &&
699 p4 submit -d "BRANCH1/B1f3" &&
701 echo b1f4 >branch1/b1f4 &&
702 p4 add branch1/b1f4 &&
703 p4 submit -d "branch1/b1f4"
707 # Check that files are properly split across branches when ignorecase is set
708 test_expect_success
!CASE_INSENSITIVE_FS
'git p4 clone, branchList branch definition, ignorecase' '
709 test_when_finished cleanup_git &&
710 test_create_repo "$git" &&
713 git config git-p4.branchList main:branch1 &&
714 git config --type=bool core.ignoreCase true &&
715 git p4 clone --dest=. --detect-branches //depot@all &&
717 git log --all --graph --decorate --stat &&
719 git reset --hard p4/master &&
720 test_path_is_file mf1 &&
721 test_path_is_file mf2 &&
722 test_path_is_missing B1f3 &&
723 test_path_is_missing b1f4 &&
725 git reset --hard p4/depot/branch1 &&
726 test_path_is_file mf1 &&
727 test_path_is_missing mf2 &&
728 test_path_is_file B1f3 &&
729 test_path_is_file b1f4
733 # Check that files are properly split across branches when ignorecase is set, use-client-spec case
734 test_expect_success
!CASE_INSENSITIVE_FS
'git p4 clone with client-spec, branchList branch definition, ignorecase' '
735 client_view "//depot/... //client/..." &&
736 test_when_finished cleanup_git &&
737 test_create_repo "$git" &&
740 git config git-p4.branchList main:branch1 &&
741 git config --type=bool core.ignoreCase true &&
742 git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
744 git log --all --graph --decorate --stat &&
746 git reset --hard p4/master &&
747 test_path_is_file mf1 &&
748 test_path_is_file mf2 &&
749 test_path_is_missing B1f3 &&
750 test_path_is_missing b1f4 &&
752 git reset --hard p4/depot/branch1 &&
753 test_path_is_file mf1 &&
754 test_path_is_missing mf2 &&
755 test_path_is_file B1f3 &&
756 test_path_is_file b1f4