diff options
author | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-09-28 01:47:49 +0200 |
---|---|---|
committer | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-09-28 03:35:39 +0200 |
commit | cf2335af23fb693549d6c4e72b65f97afddc5f64 (patch) | |
tree | 4198d6dd1dccc7608eccabd90367edb17f2e4b1c /git/index/fun.py | |
parent | a5db3d3c49ebe559cb80983d7bb855d4adf1b887 (diff) | |
download | gitpython-cf2335af23fb693549d6c4e72b65f97afddc5f64.tar.gz |
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.
Diffstat (limited to 'git/index/fun.py')
-rw-r--r-- | git/index/fun.py | 39 |
1 files changed, 22 insertions, 17 deletions
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 |