t9801: check git-p4's branch detection with client spec enabled

Add failing scenario when branch detection (--detect-branches) is enabled together with use client spec (--use-client-spec). In this specific scenario git-p4 will break when the Perforce client view removes part of the depot path, as in the following example: //depot/branch1/base/... //client/branch1/... The test case also includes an extra sub-file mapping to enforce robustness check of git-p4's client view support: //depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1 Signed-off-by: Vitor Antunes <vitor.hda@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vitor Antunes committed Apr 21, 2015 at 23:49 UTC 591707a736bd5cdded81a86e50e5ca46604d8a38
1 file changed +106
t/t9801-git-p4-branch.sh
+106
@@ -504,6 +504,112 @@ test_expect_success 'use-client-spec detect-branches skips files in branches' '
504 )
505 '
506
507 +test_expect_success 'restart p4d' '
508 + kill_p4d &&
509 + start_p4d
510 +'
511 +
512 +#
513 +# 1: //depot/branch1/base/file1
514 +# //depot/branch1/base/file2
515 +# //depot/branch1/base/dir/sub_file1
516 +# 2: integrate //depot/branch1/base/... -> //depot/branch2/base/...
517 +# 3: //depot/branch1/base/file3
518 +# 4: //depot/branch1/base/file2 (edit)
519 +# 5: integrate //depot/branch1/base/... -> //depot/branch3/base/...
520 +#
521 +# Note: the client view removes the "base" folder from the workspace
522 +# and moves sub_file1 one level up.
523 +test_expect_success 'add simple p4 branches with common base folder on each branch' '
524 + (
525 + cd "$cli" &&
526 + client_view "//depot/branch1/base/... //client/branch1/..." \
527 + "//depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1" \
528 + "//depot/branch2/base/... //client/branch2/..." \
529 + "//depot/branch3/base/... //client/branch3/..." &&
530 + mkdir -p branch1 &&
531 + cd branch1 &&
532 + echo file1 >file1 &&
533 + echo file2 >file2 &&
534 + mkdir dir &&
535 + echo sub_file1 >sub_file1 &&
536 + p4 add file1 file2 sub_file1 &&
537 + p4 submit -d "Create branch1" &&
538 + p4 integrate //depot/branch1/base/... //depot/branch2/base/... &&
539 + p4 submit -d "Integrate branch2 from branch1" &&
540 + echo file3 >file3 &&
541 + p4 add file3 &&
542 + p4 submit -d "add file3 in branch1" &&
543 + p4 open file2 &&
544 + echo update >>file2 &&
545 + p4 submit -d "update file2 in branch1" &&
546 + p4 integrate //depot/branch1/base/... //depot/branch3/base/... &&
547 + p4 submit -d "Integrate branch3 from branch1"
548 + )
549 +'
550 +
551 +# Configure branches through git-config and clone them.
552 +# All files are tested to make sure branches were cloned correctly.
553 +# Finally, make an update to branch1 on P4 side to check if it is imported
554 +# correctly by git p4.
555 +# git p4 is expected to use the client view to also not include the common
556 +# "base" folder in the imported directory structure.
557 +test_expect_success 'git p4 clone simple branches with base folder on server side' '
558 + test_create_repo "$git" &&
559 + (
560 + cd "$git" &&
561 + git config git-p4.branchList branch1:branch2 &&
562 + git config --add git-p4.branchList branch1:branch3 &&
563 + git p4 clone --dest=. --use-client-spec --detect-branches //depot@all &&
564 + git log --all --graph --decorate --stat &&
565 + git reset --hard p4/depot/branch1 &&
566 + test -f file1 &&
567 + test -f file2 &&
568 + test -f file3 &&
569 + test -f sub_file1 &&
570 + grep update file2 &&
571 + git reset --hard p4/depot/branch2 &&
572 + test -f file1 &&
573 + test -f file2 &&
574 + test ! -f file3 &&
575 + test -f sub_file1 &&
576 + ! grep update file2 &&
577 + git reset --hard p4/depot/branch3 &&
578 + test -f file1 &&
579 + test -f file2 &&
580 + test -f file3 &&
581 + test -f sub_file1 &&
582 + grep update file2 &&
583 + cd "$cli" &&
584 + cd branch1 &&
585 + p4 edit file2 &&
586 + echo file2_ >>file2 &&
587 + p4 submit -d "update file2 in branch1" &&
588 + cd "$git" &&
589 + git reset --hard p4/depot/branch1 &&
590 + git p4 rebase &&
591 + grep file2_ file2
592 + )
593 +'
594 +
595 +# Now update a file in one of the branches in git and submit to P4
596 +test_expect_failure 'Update a file in git side and submit to P4 using client view' '
597 + test_when_finished cleanup_git &&
598 + (
599 + cd "$git" &&
600 + git reset --hard p4/depot/branch1 &&
601 + echo "client spec" >> file1 &&
602 + git add -u . &&
603 + git commit -m "update file1 in branch1" &&
604 + git config git-p4.skipSubmitEdit true &&
605 + git p4 submit --verbose &&
606 + cd "$cli" &&
607 + p4 sync ... &&
608 + cd branch1 &&
609 + grep "client spec" file1
610 + )
611 +'
612 +
613 test_expect_success 'kill p4d' '
614 kill_p4d
615 '