|
14 | 14 | import os
|
15 | 15 | import subprocess
|
16 | 16 |
|
17 |
| -from git.util import IndexFileSHA1Writer |
18 |
| -from git.cmd import PROC_CREATIONFLAGS |
| 17 | +from git.util import IndexFileSHA1Writer, finalize_process |
| 18 | +from git.cmd import PROC_CREATIONFLAGS, handle_process_output |
19 | 19 | from git.exc import (
|
20 | 20 | UnmergedEntriesError,
|
21 | 21 | HookExecutionError
|
@@ -71,21 +71,26 @@ def run_commit_hook(name, index):
|
71 | 71 | env = os.environ.copy()
|
72 | 72 | env['GIT_INDEX_FILE'] = index.path
|
73 | 73 | env['GIT_EDITOR'] = ':'
|
74 |
| - cmd = subprocess.Popen(hp, |
75 |
| - env=env, |
76 |
| - stdout=subprocess.PIPE, |
77 |
| - stderr=subprocess.PIPE, |
78 |
| - cwd=index.repo.working_dir, |
79 |
| - close_fds=is_posix, |
80 |
| - creationflags=PROC_CREATIONFLAGS,) |
81 |
| - stdout, stderr = cmd.communicate() |
82 |
| - cmd.stdout.close() |
83 |
| - cmd.stderr.close() |
84 |
| - |
85 |
| - if cmd.returncode != 0: |
86 |
| - stdout = force_text(stdout, defenc) |
87 |
| - stderr = force_text(stderr, defenc) |
88 |
| - raise HookExecutionError(hp, cmd.returncode, stdout, stderr) |
| 74 | + try: |
| 75 | + cmd = subprocess.Popen(hp, |
| 76 | + env=env, |
| 77 | + stdout=subprocess.PIPE, |
| 78 | + stderr=subprocess.PIPE, |
| 79 | + cwd=index.repo.working_dir, |
| 80 | + close_fds=is_posix, |
| 81 | + creationflags=PROC_CREATIONFLAGS,) |
| 82 | + except Exception as ex: |
| 83 | + raise HookExecutionError(hp, ex) |
| 84 | + else: |
| 85 | + stdout = [] |
| 86 | + stderr = [] |
| 87 | + handle_process_output(cmd, stdout.append, stderr.append, finalize_process) |
| 88 | + stdout = ''.join(stdout) |
| 89 | + stderr = ''.join(stderr) |
| 90 | + if cmd.returncode != 0: |
| 91 | + stdout = force_text(stdout, defenc) |
| 92 | + stderr = force_text(stderr, defenc) |
| 93 | + raise HookExecutionError(hp, cmd.returncode, stdout, stderr) |
89 | 94 | # end handle return code
|
90 | 95 |
|
91 | 96 |
|
|
0 commit comments