summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamas Pal <folti@balabit.com>2014-11-05 17:13:31 +0100
committerTamas Pal <folti@balabit.com>2014-11-05 17:13:31 +0100
commit48f5476867d8316ee1af55e0e7cfacacbdf0ad68 (patch)
tree0bb09c673893797115f236836ce865a6710af358
parent27c577dfd5c7f0fc75cd10ed6606674b56b405bd (diff)
downloadgitpython-48f5476867d8316ee1af55e0e7cfacacbdf0ad68.tar.gz
GitRunCommand exception can store stdout output too.
Some git commands, like git merge outputs their problems onto stdout, instead of stderr, which will be thrown away by the current setup. This change allows the GitPython commands to store the stdout's value too, in case of error.
-rw-r--r--git/cmd.py5
-rw-r--r--git/exc.py10
2 files changed, 11 insertions, 4 deletions
diff --git a/git/cmd.py b/git/cmd.py
index b3274dd8..5323a63c 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -380,7 +380,10 @@ class Git(LazyMixin):
# END handle debug printing
if with_exceptions and status != 0:
- raise GitCommandError(command, status, stderr_value)
+ if with_extended_output:
+ raise GitCommandError(command, status, stderr_value, stdout_value)
+ else:
+ raise GitCommandError(command, status, stderr_value)
# Allow access to the command's status code
if with_extended_output:
diff --git a/git/exc.py b/git/exc.py
index 3b3091e2..76d3d486 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -17,14 +17,18 @@ class NoSuchPathError(OSError):
class GitCommandError(Exception):
""" Thrown if execution of the git command fails with non-zero status code. """
- def __init__(self, command, status, stderr=None):
+ def __init__(self, command, status, stderr=None, stdout=None):
self.stderr = stderr
+ self.stdout = stdout
self.status = status
self.command = command
def __str__(self):
- return ("'%s' returned exit status %i: %s" %
- (' '.join(str(i) for i in self.command), self.status, self.stderr))
+ ret = "'%s' returned exit status %i: %s" % \
+ (' '.join(str(i) for i in self.command), self.status, self.stderr)
+ if self.stdout is not None:
+ ret += "\nstdout: %s" % self.stdout
+ return ret
class CheckoutError( Exception ):