Skip to content

GitRunCommand exception can store stdout output too. #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ def execute(self, command,
# 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:
Expand Down
10 changes: 7 additions & 3 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ):
Expand Down