From 5077fc7e4031e53f730676df4d8df5165b1d36cc Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Sun, 29 May 2016 13:34:35 +0100 Subject: Return all the stderr messge after an error is detected for pull() --- git/cmd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index c29e3485..821bf299 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -307,7 +307,7 @@ class Git(LazyMixin): def __getattr__(self, attr): return getattr(self.proc, attr) - def wait(self, stderr=None): + def wait(self, stderr=''): """Wait for the process and return its status code. :param stderr: Previously read value of stderr, in case stderr is already closed. @@ -317,7 +317,7 @@ class Git(LazyMixin): def read_all_from_possibly_closed_stream(stream): try: - return stream.read() + return stderr + stream.read() except ValueError: return stderr or '' @@ -678,7 +678,7 @@ class Git(LazyMixin): # strip trailing "\n" if stderr_value.endswith(b"\n"): stderr_value = stderr_value[:-1] - status = proc.wait() + status = proc.wait(stderr=stderr_value) # END stdout handling finally: proc.stdout.close() -- cgit v1.2.1 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 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'git/cmd.py') 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() -- cgit v1.2.1 From 4a5cebaeda2c5062fb6c727f457ee3288f6046ef Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 6 Jun 2016 10:28:29 +0100 Subject: log all the output from stdout and stderr for debugging process failures --- git/cmd.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index fb00869c..f992a399 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -69,6 +69,10 @@ else: # Documentation ## @{ +def _drop_output_handler(line): + pass + + def handle_process_output(process, stdout_handler, stderr_handler, finalizer): """Registers for notifications to lean that process output is ready to read, and dispatches lines to the respective line handlers. We are able to handle carriage returns in case progress is sent by that @@ -79,6 +83,13 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): :param stdout_handler: f(stdout_line_string), or None :param stderr_hanlder: f(stderr_line_string), or None :param finalizer: f(proc) - wait for proc to finish""" + + log.debug('handle_process_output( process=%r, stdout_handler=%r, stderr_handler=%r, finalizer=%r' + % (process, stdout_handler, stderr_handler, finalizer)) + + if stdout_handler is None: + stdout_handler = _drop_output_handler + fdmap = {process.stdout.fileno(): (stdout_handler, [b'']), process.stderr.fileno(): (stderr_handler, [b''])} @@ -119,6 +130,7 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): # end single line helper def _dispatch_lines(fno, handler, buf_list): + log.debug('fno=%d, handler=%r, buf_list=%r' % (fno, handler, buf_list)) lc = 0 for line in _read_lines_from_fno(fno, buf_list): _dispatch_single_line(line, handler) @@ -332,6 +344,7 @@ class Git(LazyMixin): if status != 0: errstr = read_all_from_possibly_closed_stream(self.proc.stderr) + log.debug('AutoInterrupt wait stderr: %r' % (errstr,)) raise GitCommandError(self.args, status, errstr) # END status handling return status @@ -618,7 +631,7 @@ class Git(LazyMixin): bufsize=-1, stdin=istream, stderr=PIPE, - stdout=PIPE if with_stdout else open(os.devnull, 'wb'), + stdout=PIPE, shell=self.USE_SHELL, close_fds=(os.name == 'posix'), # unsupported on windows universal_newlines=universal_newlines, -- cgit v1.2.1 From 6891caf73735ea465c909de8dc13129cc98c47f7 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 6 Jun 2016 10:45:16 +0100 Subject: Can get a str object from stream.read rather then bytes. Convert to the expected bytes. --- git/cmd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index f992a399..633aedcb 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -338,7 +338,10 @@ class Git(LazyMixin): def read_all_from_possibly_closed_stream(stream): try: - return stderr + stream.read() + last_stderr = stream.read() + if type(last_stderr) == unicode: + last_stderr = last_stderr.encode(defenc) + return stderr + last_stderr except ValueError: return stderr or b'' -- cgit v1.2.1