From 08a0fad2c9dcdfe0bbc980b8cd260b4be5582381 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 30 May 2016 15:49:40 +0100 Subject: Make sure that stderr is converted to bytes remove stderr for a wait() that is not the GitPython wrapper. --- git/cmd.py | 15 ++++++++++++--- git/util.py | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/git/cmd.py b/git/cmd.py index 821bf299..e3b39bda 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -307,19 +307,28 @@ class Git(LazyMixin): 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) @@ -678,7 +687,7 @@ class Git(LazyMixin): # 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() diff --git a/git/util.py b/git/util.py index 2f894576..706518b8 100644 --- a/git/util.py +++ b/git/util.py @@ -772,10 +772,10 @@ class WaitGroup(object): 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() -- cgit v1.2.1