Skip to content

Pr cmd raise with stderr on error #452

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 7 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make sure that stderr is converted to bytes
remove stderr for a wait() that is not the GitPython wrapper.
  • Loading branch information
barry-scott committed May 30, 2016
commit 08a0fad2c9dcdfe0bbc980b8cd260b4be5582381
15 changes: 12 additions & 3 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,28 @@ def __del__(self):
def __getattr__(self, attr):
return getattr(self.proc, attr)

def wait(self, stderr=''):
def wait(self, stderr=b''):
"""Wait for the process and return its status code.

:param stderr: Previously read value of stderr, in case stderr is already closed.
:warn: may deadlock if output or error pipes are used and not handled separately.
:raise GitCommandError: if the return status is not 0"""

# stderr must be a bytes object as it will
# combined with more data from the process and
# decoded by the caller
if stderr is None:
stderr = b''
elif type(stderr) == unicode:
stderr = stderr.encode(defenc)

status = self.proc.wait()

def read_all_from_possibly_closed_stream(stream):
try:
return stderr + stream.read()
except ValueError:
return stderr or ''
return stderr or b''

if status != 0:
errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
Expand Down Expand Up @@ -678,7 +687,7 @@ def _kill_process(pid):
# strip trailing "\n"
if stderr_value.endswith(b"\n"):
stderr_value = stderr_value[:-1]
status = proc.wait(stderr=stderr_value)
status = proc.wait()
# END stdout handling
finally:
proc.stdout.close()
Expand Down
4 changes: 2 additions & 2 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,10 @@ def done(self):
self.cv.notify_all()
self.cv.release()

def wait(self):
def wait(self, stderr=b''):
self.cv.acquire()
while self.count > 0:
self.cv.wait()
self.cv.wait(strerr=stderr)
self.cv.release()


Expand Down