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 <luke@diamand.org> Acked-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luke Diamand committed
Jan 19, 2012 at 09:52 UTC
52a4880bcda7780eeda5a884f73ffa83726dc982
2 files changed
+52
-4
contrib/fast-import/git-p4
+4
-4
@@ -799,7 +799,7 @@ class P4Submit(Command, P4UserMap):
799
def canChangeChangelists(self):
800
# check to see if we have p4 admin or super-user permissions, either of
801
# which are required to modify changelists.
802
- results = p4CmdList("protects %s" % self.depotPath)
802
+ results = p4CmdList(["protects", self.depotPath])
803
for r in results:
804
if r.has_key('perm'):
805
if r['perm'] == 'admin':
@@ -1758,7 +1758,7 @@ class P4Sync(Command, P4UserMap):
1758
def getLabels(self):
1759
self.labels = {}
1760
1761
- l = p4CmdList("labels %s..." % ' '.join (self.depotPaths))
1761
+ l = p4CmdList(["labels"] + ["%s..." % p for p in self.depotPaths])
1762
if len(l) > 0 and not self.silent:
1763
print "Finding files belonging to labels in %s" % `self.depotPaths`
1764
@@ -1800,7 +1800,7 @@ class P4Sync(Command, P4UserMap):
1800
command = "branches"
1801
1802
for info in p4CmdList(command):
1803
- details = p4Cmd("branch -o %s" % info["branch"])
1803
+ details = p4Cmd(["branch", "-o", info["branch"]])
1804
viewIdx = 0
1805
while details.has_key("View%s" % viewIdx):
1806
paths = details["View%s" % viewIdx].split(" ")
@@ -1938,7 +1938,7 @@ class P4Sync(Command, P4UserMap):
1938
sourceRef = self.gitRefForBranch(sourceBranch)
1939
#print "source " + sourceBranch
1940
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"])
1942
#print "branch parent: %s" % branchParentChange
1943
gitParent = self.gitCommitByP4Change(sourceRef, branchParentChange)
1944
if len(gitParent) > 0:
t/t9803-git-p4-shell-metachars.sh
+48
@@ -57,6 +57,54 @@ test_expect_success 'deleting with shell metachars' '
57
)
58
'
59
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
+
108
test_expect_success 'kill p4d' '
109
kill_p4d
110
'