git p4: handle servers without move support
Support for the "p4 move" command was added in 8e9497c (git p4: add support for 'p4 move' in P4Submit, 2012-07-12), which checks to make sure that the client and server support the command. But older versions of p4d may not handle the "-k" argument, and newer p4d allow disabling "p4 move" with a configuration setting. Check for both these cases by testing a p4 move command on bogus filenames and looking for strings in the error messages. Reported-by: Vitor Antunes <vitor.hda@gmail.com> Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Nov 23, 2012 at 17:35 UTC
249da4c0dcd0534f416e2d5da0a9923c6068e492
2 files changed
+55
-1
git-p4.py
+20
-1
@@ -129,6 +129,25 @@ def p4_has_command(cmd):
129
p.communicate()
130
return p.returncode == 0
131
132
+def p4_has_move_command():
133
+ """See if the move command exists, that it supports -k, and that
134
+ it has not been administratively disabled. The arguments
135
+ must be correct, but the filenames do not have to exist. Use
136
+ ones with wildcards so even if they exist, it will fail."""
137
+
138
+ if not p4_has_command("move"):
139
+ return False
140
+ cmd = p4_build_cmd(["move", "-k", "@from", "@to"])
141
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
142
+ (out, err) = p.communicate()
143
+ # return code will be 1 in either case
144
+ if err.find("Invalid option") >= 0:
145
+ return False
146
+ if err.find("disabled") >= 0:
147
+ return False
148
+ # assume it failed because @... was invalid changelist
149
+ return True
150
+
151
def system(cmd):
152
expand = isinstance(cmd,basestring)
153
if verbose:
@@ -894,7 +913,7 @@ class P4Submit(Command, P4UserMap):
913
self.conflict_behavior = None
914
self.isWindows = (platform.system() == "Windows")
915
self.exportLabels = False
897
- self.p4HasMoveCommand = p4_has_command("move")
916
+ self.p4HasMoveCommand = p4_has_move_command()
917
918
def check(self):
919
if len(p4CmdList("opened ...")) > 0:
t/t9814-git-p4-rename.sh
+35
@@ -199,6 +199,41 @@ test_expect_success 'detect copies' '
199
)
200
'
201
202
+# See if configurables can be set, and in particular if the run.move.allow
203
+# variable exists, which allows admins to disable the "p4 move" command.
204
+test_expect_success 'p4 configure command and run.move.allow are available' '
205
+ p4 configure show run.move.allow >out ; retval=$? &&
206
+ test $retval = 0 &&
207
+ {
208
+ egrep ^run.move.allow: out &&
209
+ test_set_prereq P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW ||
210
+ true
211
+ } || true
212
+'
213
+
214
+# If move can be disabled, turn it off and test p4 move handling
215
+test_expect_success P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW \
216
+ 'do not use p4 move when administratively disabled' '
217
+ test_when_finished "p4 configure set run.move.allow=1" &&
218
+ p4 configure set run.move.allow=0 &&
219
+ (
220
+ cd "$cli" &&
221
+ echo move-disallow-file >move-disallow-file &&
222
+ p4 add move-disallow-file &&
223
+ p4 submit -d "add move-disallow-file"
224
+ ) &&
225
+ test_when_finished cleanup_git &&
226
+ git p4 clone --dest="$git" //depot &&
227
+ (
228
+ cd "$git" &&
229
+ git config git-p4.skipSubmitEdit true &&
230
+ git config git-p4.detectRenames true &&
231
+ git mv move-disallow-file move-disallow-file-moved &&
232
+ git commit -m "move move-disallow-file" &&
233
+ git p4 submit
234
+ )
235
+'
236
+
237
test_expect_success 'kill p4d' '
238
kill_p4d
239
'