Skip to content

Commit 48f5476

Browse files
committed
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.
1 parent 27c577d commit 48f5476

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

git/cmd.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ def execute(self, command,
380380
# END handle debug printing
381381

382382
if with_exceptions and status != 0:
383-
raise GitCommandError(command, status, stderr_value)
383+
if with_extended_output:
384+
raise GitCommandError(command, status, stderr_value, stdout_value)
385+
else:
386+
raise GitCommandError(command, status, stderr_value)
384387

385388
# Allow access to the command's status code
386389
if with_extended_output:

git/exc.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ class NoSuchPathError(OSError):
1717

1818
class GitCommandError(Exception):
1919
""" Thrown if execution of the git command fails with non-zero status code. """
20-
def __init__(self, command, status, stderr=None):
20+
def __init__(self, command, status, stderr=None, stdout=None):
2121
self.stderr = stderr
22+
self.stdout = stdout
2223
self.status = status
2324
self.command = command
2425

2526
def __str__(self):
26-
return ("'%s' returned exit status %i: %s" %
27-
(' '.join(str(i) for i in self.command), self.status, self.stderr))
27+
ret = "'%s' returned exit status %i: %s" % \
28+
(' '.join(str(i) for i in self.command), self.status, self.stderr)
29+
if self.stdout is not None:
30+
ret += "\nstdout: %s" % self.stdout
31+
return ret
2832

2933

3034
class CheckoutError( Exception ):

0 commit comments

Comments
 (0)