diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py index 6d9d14d8..01aad52d 100644 --- a/pre_commit/commands/install_uninstall.py +++ b/pre_commit/commands/install_uninstall.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import io import os.path +import pipes import sys from pre_commit import output @@ -68,7 +69,7 @@ def install( skip_on_missing_conf = 'true' if skip_on_missing_conf else 'false' contents = io.open(resource_filename('hook-tmpl')).read().format( - sys_executable=sys.executable, + sys_executable=pipes.quote(sys.executable), hook_type=hook_type, hook_specific=hook_specific_contents, config_file=runner.config_file, diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl index 3a10e90c..149bb768 100644 --- a/pre_commit/resources/hook-tmpl +++ b/pre_commit/resources/hook-tmpl @@ -9,7 +9,7 @@ popd > /dev/null retv=0 args="" -ENV_PYTHON='{sys_executable}' +ENV_PYTHON={sys_executable} SKIP_ON_MISSING_CONF={skip_on_missing_conf} which pre-commit >& /dev/null diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 80e249be..2ba5ce36 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import io import os.path +import pipes import re import shutil import subprocess @@ -54,7 +55,7 @@ def test_install_pre_commit(tempdir_factory): pre_commit_contents = io.open(runner.pre_commit_path).read() pre_commit_script = resource_filename('hook-tmpl') expected_contents = io.open(pre_commit_script).read().format( - sys_executable=sys.executable, + sys_executable=pipes.quote(sys.executable), hook_type='pre-commit', hook_specific='', config_file=runner.config_file, @@ -70,7 +71,7 @@ def test_install_pre_commit(tempdir_factory): pre_push_tmpl = resource_filename('pre-push-tmpl') pre_push_template_contents = io.open(pre_push_tmpl).read() expected_contents = io.open(pre_commit_script).read().format( - sys_executable=sys.executable, + sys_executable=pipes.quote(sys.executable), hook_type='pre-push', hook_specific=pre_push_template_contents, config_file=runner.config_file,