summaryrefslogtreecommitdiff
path: root/git_remote_helpers/util.py
diff options
context:
space:
mode:
authorSverre Rabbelier <srabbelier@gmail.com>2011-07-16 15:03:31 +0200
committerJunio C Hamano <gitster@pobox.com>2011-07-19 11:17:47 -0700
commit460d10262dae14b54123ff45e7548d872ff63983 (patch)
treee1c53cb7ea5fdf097d80bf305731affdc7e09142 /git_remote_helpers/util.py
parent0fb56ce716090248ed4895aff69dd3953b00882f (diff)
downloadgit-460d10262dae14b54123ff45e7548d872ff63983.tar.gz
git-remote-testgit: fix error handling
If fast-export did not complete successfully the error handling code itself would error out. This was broken in commit 23b093ee0 (Brandon Casey, Wed Jun 9 2010, Remove python 2.5'isms). Revert that commit an introduce our own copy of check_call in util.py instead. Tested by changing 'if retcode' to 'if not retcode' temporarily. Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git_remote_helpers/util.py')
-rw-r--r--git_remote_helpers/util.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/git_remote_helpers/util.py b/git_remote_helpers/util.py
index dce83e6066..1652c65c81 100644
--- a/git_remote_helpers/util.py
+++ b/git_remote_helpers/util.py
@@ -11,6 +11,21 @@ import sys
import os
import subprocess
+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)
+
# Whether or not to show debug messages
DEBUG = False
@@ -128,6 +143,38 @@ def run_command (args, cwd = None, shell = False, add_env = None,
return (exit_code, output, errors)
+# from python2.7:subprocess.py
+def call(*popenargs, **kwargs):
+ """Run command with arguments. Wait for command to complete, then
+ return the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ retcode = call(["ls", "-l"])
+ """
+ return subprocess.Popen(*popenargs, **kwargs).wait()
+
+
+# from python2.7:subprocess.py
+def check_call(*popenargs, **kwargs):
+ """Run command with arguments. Wait for command to complete. If
+ the exit code was zero then return, otherwise raise
+ CalledProcessError. The CalledProcessError object will have the
+ return code in the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ check_call(["ls", "-l"])
+ """
+ retcode = call(*popenargs, **kwargs)
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ raise CalledProcessError(retcode, cmd)
+ return 0
+
+
def file_reader_method (missing_ok = False):
"""Decorator for simplifying reading of files.