mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Quote args in venv'd languages
This commit is contained in:
parent
9fc6a8bfed
commit
f4d251fbbe
3 changed files with 24 additions and 2 deletions
|
|
@ -1,13 +1,16 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import pipes
|
||||||
|
|
||||||
|
|
||||||
def file_args_to_stdin(file_args):
|
def file_args_to_stdin(file_args):
|
||||||
return '\0'.join(list(file_args) + [''])
|
return '\0'.join(list(file_args) + [''])
|
||||||
|
|
||||||
|
|
||||||
def run_hook(env, hook, file_args):
|
def run_hook(env, hook, file_args):
|
||||||
|
quoted_args = [pipes.quote(arg) for arg in hook['args']]
|
||||||
return env.run(
|
return env.run(
|
||||||
' '.join(['xargs', '-0', hook['entry']] + hook['args']),
|
' '.join(['xargs', '-0', hook['entry']] + quoted_args),
|
||||||
stdin=file_args_to_stdin(file_args),
|
stdin=file_args_to_stdin(file_args),
|
||||||
retcode=None,
|
retcode=None,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
-e .
|
-e .
|
||||||
|
|
||||||
|
astroid<1.3.3
|
||||||
coverage
|
coverage
|
||||||
flake8
|
flake8
|
||||||
mock
|
mock
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,10 @@ def _test_hook_repo(
|
||||||
args,
|
args,
|
||||||
expected,
|
expected,
|
||||||
expected_return_code=0,
|
expected_return_code=0,
|
||||||
|
config_kwargs=None
|
||||||
):
|
):
|
||||||
path = make_repo(tmpdir_factory, repo_path)
|
path = make_repo(tmpdir_factory, repo_path)
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path, **(config_kwargs or {}))
|
||||||
repo = Repository.create(config, store)
|
repo = Repository.create(config, store)
|
||||||
hook_dict = [
|
hook_dict = [
|
||||||
hook for repo_hook_id, hook in repo.hooks if repo_hook_id == hook_id
|
hook for repo_hook_id, hook in repo.hooks if repo_hook_id == hook_id
|
||||||
|
|
@ -47,6 +48,23 @@ def test_python_hook(tmpdir_factory, store):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_python_hook_args_with_spaces(tmpdir_factory, store):
|
||||||
|
_test_hook_repo(
|
||||||
|
tmpdir_factory, store, 'python_hooks_repo',
|
||||||
|
'foo',
|
||||||
|
[],
|
||||||
|
"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
|
||||||
|
'Hello World\n',
|
||||||
|
config_kwargs={
|
||||||
|
'hooks': [{
|
||||||
|
'id': 'foo',
|
||||||
|
'args': ['i have spaces', 'and"\'quotes', '$and !this'],
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_versioned_python_hook(tmpdir_factory, store):
|
def test_versioned_python_hook(tmpdir_factory, store):
|
||||||
_test_hook_repo(
|
_test_hook_repo(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue