From 2f2a3589cc7f4627757f5ce9fe5211a08535fb9a Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 2 May 2019 12:11:30 +0300 Subject: [PATCH] Print hook output in real time Sometimes hooks are used to run various types of linting or tests, e.g., for pre-review. These can take a while, and if they print progress indicators, it's useful to see them immediately. Previously they wouldn't be printed at all unless there was a failure, and then all output would suddenly be printed. This makes it look like git-review is hanging. If hooks want to only print output on failure, they can buffer the output themselves however they like. As far as I can tell, the new behavior matches behavior of built-in git hooks like pre-commit, which do seem to print output immediately. --- git_review/cmd.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index b248b46..db7887d 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -128,17 +128,18 @@ def run_command_status(*argv, **kwargs): else: argv = shlex.split(str(argv[0])) stdin = kwargs.pop('stdin', None) + print_directly = kwargs.pop('print_directly', False) newenv = os.environ.copy() newenv['LANG'] = 'C' newenv['LANGUAGE'] = 'C' newenv.update(kwargs) p = subprocess.Popen(argv, stdin=subprocess.PIPE if stdin else None, - stdout=subprocess.PIPE, + stdout=None if print_directly else subprocess.PIPE, stderr=subprocess.STDOUT, env=newenv, universal_newlines=True) (out, nothing) = p.communicate(stdin) - return (p.returncode, out.strip()) + return (p.returncode, '' if print_directly else out.strip()) def run_command(*argv, **kwargs): @@ -239,15 +240,12 @@ def run_custom_script(action): os.path.join(git_dir, "hooks", script_file)] for fpath in paths: if os.path.isfile(fpath) and os.access(fpath, os.X_OK): - status, output = run_command_status(fpath) + status, output = run_command_status(fpath, print_directly=True) returns.append((status, output, fpath)) for (status, output, path) in returns: if status: raise CustomScriptException(status, output, [path], {}) - elif output and VERBOSE: - print("script %s output is:" % (path)) - print(output) def git_config_get_value(section, option, default=None, as_bool=False):