diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-26 19:51:00 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-26 20:39:57 +0100 |
commit | 78a46c432b31a0ea4c12c391c404cd128df4d709 (patch) | |
tree | 41fc4f06257bddff988a6518976321e33333f69b /lib/git/cmd.py | |
parent | 5ba2aef8f59009756567a53daaf918afa851c304 (diff) | |
download | gitpython-78a46c432b31a0ea4c12c391c404cd128df4d709.tar.gz |
cmd.wait: AutoKill wrapped process will automatically raise on errors to unify error handling amongst clients using the process directly. It might be needed to add a flag allowing to easily override that
Diffstat (limited to 'lib/git/cmd.py')
-rw-r--r-- | lib/git/cmd.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py index d674224c..4b4b84af 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -42,12 +42,16 @@ class Git(object): """ Kill/Interrupt the stored process instance once this instance goes out of scope. It is used to prevent processes piling up in case iterators stop reading. - Besides all attributes are wired through to the contained process object + Besides all attributes are wired through to the contained process object. + + The wait method was overridden to perform automatic status code checking + and possibly raise. """ - __slots__= "proc" + __slots__= ("proc", "args") - def __init__(self, proc ): + def __init__(self, proc, args ): self.proc = proc + self.args = args def __del__(self): # did the process finish already so we have a return code ? @@ -64,6 +68,20 @@ class Git(object): def __getattr__(self, attr): return getattr(self.proc, attr) + + def wait(self): + """ + Wait for the process and return its status code. + + Raise + GitCommandError if the return status is not 0 + """ + status = self.proc.wait() + if status != 0: + raise GitCommandError(self.args, status, self.proc.stderr.read()) + # END status handling + return status + def __init__(self, git_dir=None): @@ -184,7 +202,7 @@ class Git(object): **extra ) if as_process: - return self.AutoInterrupt(proc) + return self.AutoInterrupt(proc, command) # Wait for the process to return status = 0 |