Skip to content

Commit 0495983

Browse files
committed
Merge branch 'va/p4-client-path'
git p4 attempts to better handle branches in Perforce. * va/p4-client-path: git-p4: improve client path detection when branches are used t9801: check git-p4's branch detection with client spec enabled
2 parents 331fe94 + cd88410 commit 0495983

File tree

2 files changed

+115
-4
lines changed

2 files changed

+115
-4
lines changed

git-p4.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,14 @@ def p4Cmd(cmd):
502502
def p4Where(depotPath):
503503
if not depotPath.endswith("/"):
504504
depotPath += "/"
505-
depotPath = depotPath + "..."
506-
outputList = p4CmdList(["where", depotPath])
505+
depotPathLong = depotPath + "..."
506+
outputList = p4CmdList(["where", depotPathLong])
507507
output = None
508508
for entry in outputList:
509509
if "depotFile" in entry:
510-
if entry["depotFile"] == depotPath:
510+
# Search for the base client side depot path, as long as it starts with the branch's P4 path.
511+
# The base path always ends with "/...".
512+
if entry["depotFile"].find(depotPath) == 0 and entry["depotFile"][-4:] == "/...":
511513
output = entry
512514
break
513515
elif "data" in entry:
@@ -1653,7 +1655,10 @@ def run(self, args):
16531655
if self.useClientSpec:
16541656
self.clientSpecDirs = getClientSpec()
16551657

1656-
if self.useClientSpec:
1658+
# Check for the existance of P4 branches
1659+
branchesDetected = (len(p4BranchesInGit().keys()) > 1)
1660+
1661+
if self.useClientSpec and not branchesDetected:
16571662
# all files are relative to the client spec
16581663
self.clientPath = getClientRoot()
16591664
else:

t/t9801-git-p4-branch.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,112 @@ test_expect_success 'use-client-spec detect-branches skips files in branches' '
504504
)
505505
'
506506

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_success '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+
507613
test_expect_success 'kill p4d' '
508614
kill_p4d
509615
'

0 commit comments

Comments
 (0)