Skip to content

Commit 52a4880

Browse files
luked99gitster
authored andcommitted
git-p4: handle p4 branches and labels containing shell chars
Don't use shell expansion when detecting branches, as it will fail if the branch name contains a shell metachar. Similarly for labels. Add additional test for branches with shell metachars. Signed-off-by: Luke Diamand <[email protected]> Acked-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8cbfc11 commit 52a4880

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

contrib/fast-import/git-p4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class P4Submit(Command, P4UserMap):
799799
def canChangeChangelists(self):
800800
# check to see if we have p4 admin or super-user permissions, either of
801801
# which are required to modify changelists.
802-
results = p4CmdList("protects %s" % self.depotPath)
802+
results = p4CmdList(["protects", self.depotPath])
803803
for r in results:
804804
if r.has_key('perm'):
805805
if r['perm'] == 'admin':
@@ -1758,7 +1758,7 @@ class P4Sync(Command, P4UserMap):
17581758
def getLabels(self):
17591759
self.labels = {}
17601760

1761-
l = p4CmdList("labels %s..." % ' '.join (self.depotPaths))
1761+
l = p4CmdList(["labels"] + ["%s..." % p for p in self.depotPaths])
17621762
if len(l) > 0 and not self.silent:
17631763
print "Finding files belonging to labels in %s" % `self.depotPaths`
17641764

@@ -1800,7 +1800,7 @@ class P4Sync(Command, P4UserMap):
18001800
command = "branches"
18011801

18021802
for info in p4CmdList(command):
1803-
details = p4Cmd("branch -o %s" % info["branch"])
1803+
details = p4Cmd(["branch", "-o", info["branch"]])
18041804
viewIdx = 0
18051805
while details.has_key("View%s" % viewIdx):
18061806
paths = details["View%s" % viewIdx].split(" ")
@@ -1938,7 +1938,7 @@ class P4Sync(Command, P4UserMap):
19381938
sourceRef = self.gitRefForBranch(sourceBranch)
19391939
#print "source " + sourceBranch
19401940

1941-
branchParentChange = int(p4Cmd("changes -m 1 %s...@1,%s" % (sourceDepotPath, firstChange))["change"])
1941+
branchParentChange = int(p4Cmd(["changes", "-m", "1", "%s...@1,%s" % (sourceDepotPath, firstChange)])["change"])
19421942
#print "branch parent: %s" % branchParentChange
19431943
gitParent = self.gitCommitByP4Change(sourceRef, branchParentChange)
19441944
if len(gitParent) > 0:

t/t9803-git-p4-shell-metachars.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,54 @@ test_expect_success 'deleting with shell metachars' '
5757
)
5858
'
5959

60+
# Create a branch with a shell metachar in its name
61+
#
62+
# 1. //depot/main
63+
# 2. //depot/branch$3
64+
65+
test_expect_success 'branch with shell char' '
66+
test_when_finished cleanup_git &&
67+
test_create_repo "$git" &&
68+
(
69+
cd "$cli" &&
70+
71+
mkdir -p main &&
72+
73+
echo f1 >main/f1 &&
74+
p4 add main/f1 &&
75+
p4 submit -d "main/f1" &&
76+
77+
p4 integrate //depot/main/... //depot/branch\$3/... &&
78+
p4 submit -d "integrate main to branch\$3" &&
79+
80+
echo f1 >branch\$3/shell_char_branch_file &&
81+
p4 add branch\$3/shell_char_branch_file &&
82+
p4 submit -d "branch\$3/shell_char_branch_file" &&
83+
84+
p4 branch -i <<-EOF &&
85+
Branch: branch\$3
86+
View: //depot/main/... //depot/branch\$3/...
87+
EOF
88+
89+
p4 edit main/f1 &&
90+
echo "a change" >> main/f1 &&
91+
p4 submit -d "a change" main/f1 &&
92+
93+
p4 integrate -b branch\$3 &&
94+
p4 resolve -am branch\$3/... &&
95+
p4 submit -d "integrate main to branch\$3" &&
96+
97+
cd "$git" &&
98+
99+
git config git-p4.branchList main:branch\$3 &&
100+
"$GITP4" clone --dest=. --detect-branches //depot@all &&
101+
git log --all --graph --decorate --stat &&
102+
git reset --hard p4/depot/branch\$3 &&
103+
test -f shell_char_branch_file &&
104+
test -f f1
105+
)
106+
'
107+
60108
test_expect_success 'kill p4d' '
61109
kill_p4d
62110
'

0 commit comments

Comments
 (0)