Skip to content

Commit 61606cf

Browse files
committed
Allow spaces in system hooks. Closes #95.
1 parent 53e316a commit 61606cf

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

pre_commit/languages/system.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import shlex
2+
3+
14
ENVIRONMENT_DIR = None
25

36

@@ -7,7 +10,7 @@ def install_environment(repo_cmd_runner):
710

811
def run_hook(repo_cmd_runner, hook, file_args):
912
return repo_cmd_runner.run(
10-
['xargs', hook['entry']] + hook['args'],
13+
['xargs'] + shlex.split(hook['entry']) + hook['args'],
1114
# TODO: this is duplicated in pre_commit/languages/helpers.py
1215
stdin='\n'.join(list(file_args) + ['']),
1316
retcode=None,

testing/resources/prints_cwd_repo/setup.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- id: system-hook-with-spaces
2+
name: System hook with spaces
3+
entry: /usr/bin/python -c 'import sys; print("Hello World")'
4+
language: system

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ def failing_hook_repo(dummy_git_repo):
102102
yield _make_repo(dummy_git_repo, 'failing_hook_repo')
103103

104104

105+
@pytest.yield_fixture
106+
def system_hook_with_spaces_repo(dummy_git_repo):
107+
yield _make_repo(dummy_git_repo, 'system_hook_with_spaces_repo')
108+
109+
105110
def _make_config(path, hook_id, file_regex):
106111
config = {
107112
'repo': path,
@@ -138,6 +143,13 @@ def config_for_script_hooks_repo(script_hooks_repo):
138143
yield _make_config(script_hooks_repo, 'bash_hook', '')
139144

140145

146+
@pytest.yield_fixture
147+
def config_for_system_hook_with_spaces(system_hook_with_spaces_repo):
148+
yield _make_config(
149+
system_hook_with_spaces_repo, 'system-hook-with-spaces', '',
150+
)
151+
152+
141153
def _make_repo_from_configs(*configs):
142154
with open(C.CONFIG_FILE, 'w') as config_file:
143155
yaml.dump(

tests/repository_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def test_cwd_of_hook(config_for_prints_cwd_repo, store):
4040
assert ret[1] == repo.repo_url + '\n'
4141

4242

43+
@pytest.mark.integration
44+
def test_system_hook_with_spaces(config_for_system_hook_with_spaces, store):
45+
repo = Repository.create(config_for_system_hook_with_spaces, store)
46+
ret = repo.run_hook('system-hook-with-spaces', [])
47+
assert ret[0] == 0
48+
assert ret[1] == 'Hello World\n'
49+
50+
4351
@skipif_slowtests_false
4452
@pytest.mark.integration
4553
def test_run_a_node_hook(config_for_node_hooks_repo, store):

0 commit comments

Comments
 (0)