Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exit code for commands terminated by signals #2971

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pre_commit/xargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def run_cmd_partition(
results = thread_map(run_cmd_partition, partitions)

for proc_retcode, proc_out, _ in results:
retcode = max(retcode, proc_retcode)
if abs(proc_retcode) > abs(retcode):
retcode = proc_retcode
Comment on lines -173 to +174
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this over something like retcode = retcode or proc_retcode just so that it would consistently pick the same exit status from a set of exit statuses. If you prefer some other way of selecting which to use, I can change it to that.

stdout += proc_out

return retcode, stdout
9 changes: 9 additions & 0 deletions tests/xargs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def test_xargs_retcode_normal():
assert ret == 5


@pytest.mark.xfail(sys.platform == 'win32', reason='posix only')
def test_xargs_retcode_killed_by_signal():
ret, _ = xargs.xargs(
parse_shebang.normalize_cmd(('bash', '-c', 'kill -9 $$', '--')),
('foo', 'bar'),
)
assert ret == -9


def test_xargs_concurrency():
bash_cmd = parse_shebang.normalize_cmd(('bash', '-c'))
print_pid = ('sleep 0.5 && echo $$',)
Expand Down