3 test_description
='git p4 tests for p4 branches'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
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 master -- >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 master -- >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 master -- >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 master -- >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 master -- >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
'import depot, branch detection, branchList branch definition' '
133 test_when_finished cleanup_git &&
134 test_create_repo "$git" &&
137 git config git-p4.branchList main:branch1 &&
138 git p4 clone --dest=. --detect-branches //depot@all &&
140 git log --oneline --graph --decorate --all &&
143 git rev-list master -- >wc &&
144 test_line_count = 4 wc &&
146 # 3 main, 1 integrate, 1 on branch2
147 git rev-list p4/depot/branch2 >wc &&
148 test_line_count = 5 wc &&
150 # 2 main, 1 integrate, 1 on branch1
151 git rev-list p4/depot/branch1 >wc &&
152 test_line_count = 4 wc
156 test_expect_success
'restart p4d' '
157 stop_and_cleanup_p4d &&
162 # 1: //depot/branch1/file1
163 # //depot/branch1/file2
164 # 2: integrate //depot/branch1/... -> //depot/branch2/...
165 # 3: //depot/branch1/file3
166 # 4: //depot/branch1/file2 (edit)
167 # 5: integrate //depot/branch1/... -> //depot/branch3/...
169 ## Create a simple branch structure in P4 depot.
170 test_expect_success
'add simple p4 branches' '
177 p4 add file1 file2 &&
178 p4 submit -d "Create branch1" &&
179 p4 integrate //depot/branch1/... //depot/branch2/... &&
180 p4 submit -d "Integrate branch2 from branch1" &&
183 p4 submit -d "add file3 in branch1" &&
185 echo update >>file2 &&
186 p4 submit -d "update file2 in branch1" &&
187 p4 integrate //depot/branch1/... //depot/branch3/... &&
188 p4 submit -d "Integrate branch3 from branch1"
192 # Configure branches through git-config and clone them.
193 # All files are tested to make sure branches were cloned correctly.
194 # Finally, make an update to branch1 on P4 side to check if it is imported
195 # correctly by git p4.
196 test_expect_success
'git p4 clone simple branches' '
197 test_when_finished cleanup_git &&
198 test_create_repo "$git" &&
201 git config git-p4.branchList branch1:branch2 &&
202 git config --add git-p4.branchList branch1:branch3 &&
203 git p4 clone --dest=. --detect-branches //depot@all &&
204 git log --all --graph --decorate --stat &&
205 git reset --hard p4/depot/branch1 &&
210 git reset --hard p4/depot/branch2 &&
214 ! grep update file2 &&
215 git reset --hard p4/depot/branch3 &&
223 echo file2_ >>file2 &&
224 p4 submit -d "update file2 in branch1" &&
226 git reset --hard p4/depot/branch1 &&
232 # Create a complex branch structure in P4 depot to check if they are correctly
233 # cloned. The branches are created from older changelists to check if git p4 is
234 # able to correctly detect them.
235 # The final expected structure is:
238 # | `- file2 (updated)
245 # | `- file2 (updated)
254 test_expect_success
'git p4 add complex branches' '
257 changelist=$(p4 changes -m1 //depot/... | cut -d" " -f2) &&
258 changelist=$(($changelist - 5)) &&
259 p4 integrate //depot/branch1/...@$changelist //depot/branch4/... &&
260 p4 submit -d "Integrate branch4 from branch1@${changelist}" &&
261 changelist=$(($changelist + 2)) &&
262 p4 integrate //depot/branch1/...@$changelist //depot/branch5/... &&
263 p4 submit -d "Integrate branch5 from branch1@${changelist}"
267 # Configure branches through git-config and clone them. git p4 will only be able
268 # to clone the original structure if it is able to detect the origin changelist
270 test_expect_success
'git p4 clone complex branches' '
271 test_when_finished cleanup_git &&
272 test_create_repo "$git" &&
275 git config git-p4.branchList branch1:branch2 &&
276 git config --add git-p4.branchList branch1:branch3 &&
277 git config --add git-p4.branchList branch1:branch4 &&
278 git config --add git-p4.branchList branch1:branch5 &&
279 git p4 clone --dest=. --detect-branches //depot@all &&
280 git log --all --graph --decorate --stat &&
281 git reset --hard p4/depot/branch1 &&
282 test_path_is_file file1 &&
283 test_path_is_file file2 &&
284 test_path_is_file file3 &&
286 git reset --hard p4/depot/branch2 &&
287 test_path_is_file file1 &&
288 test_path_is_file file2 &&
289 test_path_is_missing file3 &&
290 ! grep update file2 &&
291 git reset --hard p4/depot/branch3 &&
292 test_path_is_file file1 &&
293 test_path_is_file file2 &&
294 test_path_is_file file3 &&
296 git reset --hard p4/depot/branch4 &&
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/branch5 &&
302 test_path_is_file file1 &&
303 test_path_is_file file2 &&
304 test_path_is_file file3 &&
305 ! grep update file2 &&
306 test_must_fail git show-ref --verify refs/git-p4-tmp
310 # Move branch3/file3 to branch4/file3 in a single changelist
311 test_expect_success
'git p4 submit to two branches in a single changelist' '
314 p4 integrate //depot/branch3/file3 //depot/branch4/file3 &&
315 p4 delete //depot/branch3/file3 &&
316 p4 submit -d "Move branch3/file3 to branch4/file3"
320 # Confirm that changes to two branches done in a single changelist
321 # are correctly imported by git p4
322 test_expect_success
'git p4 sync changes to two branches in the same changelist' '
323 test_when_finished cleanup_git &&
324 test_create_repo "$git" &&
327 git config git-p4.branchList branch1:branch2 &&
328 git config --add git-p4.branchList branch1:branch3 &&
329 git config --add git-p4.branchList branch1:branch4 &&
330 git config --add git-p4.branchList branch1:branch5 &&
331 git p4 clone --dest=. --detect-branches //depot@all &&
332 git log --all --graph --decorate --stat &&
333 git reset --hard p4/depot/branch1 &&
334 test_path_is_file file1 &&
335 test_path_is_file file2 &&
336 test_path_is_file file3 &&
338 git reset --hard p4/depot/branch2 &&
339 test_path_is_file file1 &&
340 test_path_is_file file2 &&
341 test_path_is_missing file3 &&
342 ! grep update file2 &&
343 git reset --hard p4/depot/branch3 &&
344 test_path_is_file file1 &&
345 test_path_is_file file2 &&
346 test_path_is_missing file3 &&
348 git reset --hard p4/depot/branch4 &&
349 test_path_is_file file1 &&
350 test_path_is_file file2 &&
351 test_path_is_file file3 &&
352 ! grep update file2 &&
353 git reset --hard p4/depot/branch5 &&
354 test_path_is_file file1 &&
355 test_path_is_file file2 &&
356 test_path_is_file file3 &&
357 ! grep update file2 &&
358 test_must_fail git show-ref --verify refs/git-p4-tmp
362 # Create a branch by integrating a single file
363 test_expect_success
'git p4 file subset branch' '
366 p4 integrate //depot/branch1/file1 //depot/branch6/file1 &&
367 p4 submit -d "Integrate file1 alone from branch1 to branch6"
371 # Check if git p4 creates a new branch containing a single file,
372 # instead of keeping the old files from the original branch
373 test_expect_failure
'git p4 clone file subset branch' '
374 test_when_finished cleanup_git &&
375 test_create_repo "$git" &&
378 git config git-p4.branchList branch1:branch2 &&
379 git config --add git-p4.branchList branch1:branch3 &&
380 git config --add git-p4.branchList branch1:branch4 &&
381 git config --add git-p4.branchList branch1:branch5 &&
382 git config --add git-p4.branchList branch1:branch6 &&
383 git p4 clone --dest=. --detect-branches //depot@all &&
384 git log --all --graph --decorate --stat &&
385 git reset --hard p4/depot/branch1 &&
386 test_path_is_file file1 &&
387 test_path_is_file file2 &&
388 test_path_is_file file3 &&
390 git reset --hard p4/depot/branch2 &&
391 test_path_is_file file1 &&
392 test_path_is_file file2 &&
393 test_path_is_missing file3 &&
394 ! grep update file2 &&
395 git reset --hard p4/depot/branch3 &&
396 test_path_is_file file1 &&
397 test_path_is_file file2 &&
398 test_path_is_missing file3 &&
400 git reset --hard p4/depot/branch4 &&
401 test_path_is_file file1 &&
402 test_path_is_file file2 &&
403 test_path_is_file file3 &&
404 ! grep update file2 &&
405 git reset --hard p4/depot/branch5 &&
406 test_path_is_file file1 &&
407 test_path_is_file file2 &&
408 test_path_is_file file3 &&
409 ! grep update file2 &&
410 git reset --hard p4/depot/branch6 &&
411 test_path_is_file file1 &&
412 test_path_is_missing file2 &&
413 test_path_is_missing file3
417 # Check that excluded files are omitted during import
418 test_expect_success
'git p4 clone complex branches with excluded files' '
419 test_when_finished cleanup_git &&
420 test_create_repo "$git" &&
423 git config git-p4.branchList branch1:branch2 &&
424 git config --add git-p4.branchList branch1:branch3 &&
425 git config --add git-p4.branchList branch1:branch4 &&
426 git config --add git-p4.branchList branch1:branch5 &&
427 git config --add git-p4.branchList branch1:branch6 &&
428 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 &&
429 git log --all --graph --decorate --stat &&
430 git reset --hard p4/depot/branch1 &&
431 test_path_is_file file1 &&
432 test_path_is_missing file2 &&
433 test_path_is_file file3 &&
434 git reset --hard p4/depot/branch2 &&
435 test_path_is_file file1 &&
436 test_path_is_missing file2 &&
437 test_path_is_missing file3 &&
438 git reset --hard p4/depot/branch3 &&
439 test_path_is_file file1 &&
440 test_path_is_missing file2 &&
441 test_path_is_missing file3 &&
442 git reset --hard p4/depot/branch4 &&
443 test_path_is_file file1 &&
444 test_path_is_missing file2 &&
445 test_path_is_file file3 &&
446 git reset --hard p4/depot/branch5 &&
447 test_path_is_file file1 &&
448 test_path_is_missing file2 &&
449 test_path_is_file file3 &&
450 git reset --hard p4/depot/branch6 &&
451 test_path_is_file file1 &&
452 test_path_is_missing file2 &&
453 test_path_is_missing file3
457 # From a report in http://stackoverflow.com/questions/11893688
458 # where --use-client-spec caused branch prefixes not to be removed;
459 # every file in git appeared into a subdirectory of the branch name.
460 test_expect_success
'use-client-spec detect-branches setup' '
465 client_view "//depot/usecs/... //client/..." &&
467 echo b1/b1-file1 >b1/b1-file1 &&
468 p4 add b1/b1-file1 &&
469 p4 submit -d "b1/b1-file1" &&
471 p4 integrate //depot/usecs/b1/... //depot/usecs/b2/... &&
472 p4 submit -d "b1 -> b2" &&
473 p4 branch -i <<-EOF &&
475 View: //depot/usecs/b1/... //depot/usecs/b2/...
478 echo b2/b2-file2 >b2/b2-file2 &&
479 p4 add b2/b2-file2 &&
480 p4 submit -d "b2/b2-file2"
484 test_expect_success
'use-client-spec detect-branches files in top-level' '
485 test_when_finished cleanup_git &&
486 test_create_repo "$git" &&
489 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
490 git checkout -b master p4/usecs/b1 &&
491 test_path_is_file b1-file1 &&
492 test_path_is_missing b2-file2 &&
493 test_path_is_missing b1 &&
494 test_path_is_missing b2 &&
496 git checkout -b b2 p4/usecs/b2 &&
497 test_path_is_file b1-file1 &&
498 test_path_is_file b2-file2 &&
499 test_path_is_missing b1 &&
500 test_path_is_missing b2
504 test_expect_success
'use-client-spec detect-branches skips branches setup' '
508 p4 integrate //depot/usecs/b1/... //depot/usecs/b3/... &&
509 p4 submit -d "b1 -> b3" &&
510 p4 branch -i <<-EOF &&
512 View: //depot/usecs/b1/... //depot/usecs/b3/...
515 echo b3/b3-file3_1 >b3/b3-file3_1 &&
516 echo b3/b3-file3_2 >b3/b3-file3_2 &&
517 p4 add b3/b3-file3_1 &&
518 p4 add b3/b3-file3_2 &&
519 p4 submit -d "b3/b3-file3_1 b3/b3-file3_2"
523 test_expect_success
'use-client-spec detect-branches skips branches' '
524 client_view "//depot/usecs/... //client/..." \
525 "-//depot/usecs/b3/... //client/b3/..." &&
526 test_when_finished cleanup_git &&
527 test_create_repo "$git" &&
530 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
531 test_must_fail git rev-parse refs/remotes/p4/usecs/b3
535 test_expect_success
'use-client-spec detect-branches skips files in branches' '
536 client_view "//depot/usecs/... //client/..." \
537 "-//depot/usecs/b3/b3-file3_1 //client/b3/b3-file3_1" &&
538 test_when_finished cleanup_git &&
539 test_create_repo "$git" &&
542 git p4 sync --detect-branches --use-client-spec //depot/usecs@all &&
543 git checkout -b master p4/usecs/b3 &&
544 test_path_is_file b1-file1 &&
545 test_path_is_file b3-file3_2 &&
546 test_path_is_missing b3-file3_1
550 test_expect_success
'restart p4d' '
551 stop_and_cleanup_p4d &&
556 # 1: //depot/branch1/base/file1
557 # //depot/branch1/base/file2
558 # //depot/branch1/base/dir/sub_file1
559 # 2: integrate //depot/branch1/base/... -> //depot/branch2/base/...
560 # 3: //depot/branch1/base/file3
561 # 4: //depot/branch1/base/file2 (edit)
562 # 5: integrate //depot/branch1/base/... -> //depot/branch3/base/...
564 # Note: the client view removes the "base" folder from the workspace
565 # and moves sub_file1 one level up.
566 test_expect_success
'add simple p4 branches with common base folder on each branch' '
569 client_view "//depot/branch1/base/... //client/branch1/..." \
570 "//depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1" \
571 "//depot/branch2/base/... //client/branch2/..." \
572 "//depot/branch3/base/... //client/branch3/..." &&
578 echo sub_file1 >sub_file1 &&
579 p4 add file1 file2 sub_file1 &&
580 p4 submit -d "Create branch1" &&
581 p4 integrate //depot/branch1/base/... //depot/branch2/base/... &&
582 p4 submit -d "Integrate branch2 from branch1" &&
585 p4 submit -d "add file3 in branch1" &&
587 echo update >>file2 &&
588 p4 submit -d "update file2 in branch1" &&
589 p4 integrate //depot/branch1/base/... //depot/branch3/base/... &&
590 p4 submit -d "Integrate branch3 from branch1"
594 # Configure branches through git-config and clone them.
595 # All files are tested to make sure branches were cloned correctly.
596 # Finally, make an update to branch1 on P4 side to check if it is imported
597 # correctly by git p4.
598 # git p4 is expected to use the client view to also not include the common
599 # "base" folder in the imported directory structure.
600 test_expect_success
'git p4 clone simple branches with base folder on server side' '
601 test_create_repo "$git" &&
604 git config git-p4.branchList branch1:branch2 &&
605 git config --add git-p4.branchList branch1:branch3 &&
606 git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
607 git log --all --graph --decorate --stat &&
608 git reset --hard p4/depot/branch1 &&
614 git reset --hard p4/depot/branch2 &&
619 ! grep update file2 &&
620 git reset --hard p4/depot/branch3 &&
629 echo file2_ >>file2 &&
630 p4 submit -d "update file2 in branch1" &&
632 git reset --hard p4/depot/branch1 &&
638 # Now update a file in one of the branches in git and submit to P4
639 test_expect_success
'Update a file in git side and submit to P4 using client view' '
640 test_when_finished cleanup_git &&
643 git reset --hard p4/depot/branch1 &&
644 echo "client spec" >> file1 &&
646 git commit -m "update file1 in branch1" &&
647 git config git-p4.skipSubmitEdit true &&
648 git p4 submit --verbose &&
652 grep "client spec" file1
656 test_expect_success
'restart p4d (case folding enabled)' '
657 stop_and_cleanup_p4d &&
662 # 1: //depot/main/mf1
663 # 2: integrate //depot/main/... -> //depot/branch1/...
664 # 3: //depot/main/mf2
665 # 4: //depot/BRANCH1/B1f3
666 # 5: //depot/branch1/b1f4
668 test_expect_success
!CASE_INSENSITIVE_FS
'basic p4 branches for case folding' '
673 echo mf1 >main/mf1 &&
675 p4 submit -d "main/mf1" &&
677 p4 integrate //depot/main/... //depot/branch1/... &&
678 p4 submit -d "integrate main to branch1" &&
680 echo mf2 >main/mf2 &&
682 p4 submit -d "main/mf2" &&
685 echo B1f3 >BRANCH1/B1f3 &&
686 p4 add BRANCH1/B1f3 &&
687 p4 submit -d "BRANCH1/B1f3" &&
689 echo b1f4 >branch1/b1f4 &&
690 p4 add branch1/b1f4 &&
691 p4 submit -d "branch1/b1f4"
695 # Check that files are properly split across branches when ignorecase is set
696 test_expect_success
!CASE_INSENSITIVE_FS
'git p4 clone, branchList branch definition, ignorecase' '
697 test_when_finished cleanup_git &&
698 test_create_repo "$git" &&
701 git config git-p4.branchList main:branch1 &&
702 git config --type=bool core.ignoreCase true &&
703 git p4 clone --dest=. --detect-branches //depot@all &&
705 git log --all --graph --decorate --stat &&
707 git reset --hard p4/master &&
708 test_path_is_file mf1 &&
709 test_path_is_file mf2 &&
710 test_path_is_missing B1f3 &&
711 test_path_is_missing b1f4 &&
713 git reset --hard p4/depot/branch1 &&
714 test_path_is_file mf1 &&
715 test_path_is_missing mf2 &&
716 test_path_is_file B1f3 &&
717 test_path_is_file b1f4
721 # Check that files are properly split across branches when ignorecase is set, use-client-spec case
722 test_expect_success
!CASE_INSENSITIVE_FS
'git p4 clone with client-spec, branchList branch definition, ignorecase' '
723 client_view "//depot/... //client/..." &&
724 test_when_finished cleanup_git &&
725 test_create_repo "$git" &&
728 git config git-p4.branchList main:branch1 &&
729 git config --type=bool core.ignoreCase true &&
730 git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
732 git log --all --graph --decorate --stat &&
734 git reset --hard p4/master &&
735 test_path_is_file mf1 &&
736 test_path_is_file mf2 &&
737 test_path_is_missing B1f3 &&
738 test_path_is_missing b1f4 &&
740 git reset --hard p4/depot/branch1 &&
741 test_path_is_file mf1 &&
742 test_path_is_missing mf2 &&
743 test_path_is_file B1f3 &&
744 test_path_is_file b1f4