X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=git-p4.py;h=0682e61e90dca3f88f399c20aa19c5336274bc95;hb=f3500825257b441134bd99b08bab3b6fd1cb4f51;hp=551aec9417401dcd7ef526dd6c9b554e5194f861;hpb=80ff618049cde1f1e48cf0fa3435c0e09be36756;p=git.git diff --git a/git-p4.py b/git-p4.py index 551aec941..0682e61e9 100755 --- a/git-p4.py +++ b/git-p4.py @@ -12,6 +12,21 @@ import optparse, sys, os, marshal, subprocess, shelve import tempfile, getopt, os.path, time, platform import re, shutil +try: + from subprocess import CalledProcessError +except ImportError: + # from python2.7:subprocess.py + # Exception classes used by this module. + class CalledProcessError(Exception): + """This exception is raised when a process run by check_call() returns + a non-zero exit status. The exit status will be stored in the + returncode attribute.""" + def __init__(self, returncode, cmd): + self.returncode = returncode + self.cmd = cmd + def __str__(self): + return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode) + verbose = False # Only labels/tags matching this will be imported/exported @@ -152,13 +167,17 @@ def system(cmd): expand = isinstance(cmd,basestring) if verbose: sys.stderr.write("executing %s\n" % str(cmd)) - subprocess.check_call(cmd, shell=expand) + retcode = subprocess.call(cmd, shell=expand) + if retcode: + raise CalledProcessError(retcode, cmd) def p4_system(cmd): """Specifically invoke p4 as the system command. """ real_cmd = p4_build_cmd(cmd) expand = isinstance(real_cmd, basestring) - subprocess.check_call(real_cmd, shell=expand) + retcode = subprocess.call(real_cmd, shell=expand) + if retcode: + raise CalledProcessError(retcode, real_cmd) def p4_integrate(src, dest): p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)]) @@ -742,7 +761,8 @@ def wildcard_encode(path): return path def wildcard_present(path): - return path.translate(None, "*#@%") != path + m = re.search("[*#@%]", path) + return m is not None class Command: def __init__(self): @@ -3103,7 +3123,9 @@ class P4Clone(P4Sync): init_cmd = [ "git", "init" ] if self.cloneBare: init_cmd.append("--bare") - subprocess.check_call(init_cmd) + retcode = subprocess.call(init_cmd) + if retcode: + raise CalledProcessError(retcode, init_cmd) if not P4Sync.run(self, depotPaths): return False