8000 Fix exit code for commands terminated by signals · pre-commit/pre-commit@5a4b5b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a4b5b1

Browse files
committed
Fix exit code for commands terminated by signals
Fixes #2970
1 parent a1f1d19 commit 5a4b5b1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pre_commit/xargs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def run_cmd_partition(
170170
results = thread_map(run_cmd_partition, partitions)
171171

172172
for proc_retcode, proc_out, _ in results:
173-
retcode = max(retcode, proc_retcode)
173+
if abs(proc_retcode) > abs(retcode):
174+
retcode = proc_retcode
174175
stdout += proc_out
175176

176177
return retcode, stdout

tests/xargs_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ def test_xargs_retcode_normal():
147147
assert ret == 5
148148

149149

150+
@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
151+
def test_xargs_retcode_killed_by_signal():
152+
ret, _ = xargs.xargs(
153+
parse_shebang.normalize_cmd(('bash', '-c', 'kill -9 $$', '--')),
154+
('foo', 'bar'),
155+
)
156+
assert ret == -9
157+
158+
150159
def test_xargs_concurrency():
151160
bash_cmd = parse_shebang.normalize_cmd(('bash', '-c'))
152161
print_pid = ('sleep 0.5 && echo $$',)

0 commit comments

Comments
 (0)
0