From cf2335af23fb693549d6c4e72b65f97afddc5f64 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 28 Sep 2016 01:47:49 +0200 Subject: Win, hook, #519: Consume Hook Popen-proc out of GIL + HookException thrown on Popen, and were missed on Windows. + No SHELL on Popen?? + Minor fixes: + Try harder to delete trees - no remorses. + Simplify exception reprs. + Unittest-ize test_index assertions. --- git/index/fun.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'git/index/fun.py') diff --git a/git/index/fun.py b/git/index/fun.py index 80db46b1..0179625a 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -14,8 +14,8 @@ from io import BytesIO import os import subprocess -from git.util import IndexFileSHA1Writer -from git.cmd import PROC_CREATIONFLAGS +from git.util import IndexFileSHA1Writer, finalize_process +from git.cmd import PROC_CREATIONFLAGS, handle_process_output from git.exc import ( UnmergedEntriesError, HookExecutionError @@ -71,21 +71,26 @@ def run_commit_hook(name, index): env = os.environ.copy() env['GIT_INDEX_FILE'] = index.path env['GIT_EDITOR'] = ':' - cmd = subprocess.Popen(hp, - env=env, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - cwd=index.repo.working_dir, - close_fds=is_posix, - creationflags=PROC_CREATIONFLAGS,) - stdout, stderr = cmd.communicate() - cmd.stdout.close() - cmd.stderr.close() - - if cmd.returncode != 0: - stdout = force_text(stdout, defenc) - stderr = force_text(stderr, defenc) - raise HookExecutionError(hp, cmd.returncode, stdout, stderr) + try: + cmd = subprocess.Popen(hp, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=index.repo.working_dir, + close_fds=is_posix, + creationflags=PROC_CREATIONFLAGS,) + except Exception as ex: + raise HookExecutionError(hp, ex) + else: + stdout = [] + stderr = [] + handle_process_output(cmd, stdout.append, stderr.append, finalize_process) + stdout = ''.join(stdout) + stderr = ''.join(stderr) + if cmd.returncode != 0: + stdout = force_text(stdout, defenc) + stderr = force_text(stderr, defenc) + raise HookExecutionError(hp, cmd.returncode, stdout, stderr) # end handle return code -- cgit v1.2.3