From 7988eb7f3079ee92c36ae7c34962ac5083c96694 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Fri, 19 Nov 2021 12:13:37 -0500 Subject: [PATCH] Suggest usable call when exec files lack shebang on Windows Resolves Issue #686 --- pre_commit_hooks/check_executables_have_shebangs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/check_executables_have_shebangs.py b/pre_commit_hooks/check_executables_have_shebangs.py index 33f75c02..0a059f80 100644 --- a/pre_commit_hooks/check_executables_have_shebangs.py +++ b/pre_commit_hooks/check_executables_have_shebangs.py @@ -60,10 +60,12 @@ def has_shebang(path: str) -> int: def _message(path: str) -> None: + is_windows = sys.platform == 'win32' + remove_execute_permissions_command = 'git add --chmod=-x' if is_windows else 'chmod -x' print( f'{path}: marked executable but has no (or invalid) shebang!\n' f" If it isn't supposed to be executable, try: " - f'`chmod -x {shlex.quote(path)}`\n' + f'`{remove_execute_permissions_command} {shlex.quote(path)}`\n' f' If it is supposed to be executable, double-check its shebang.', file=sys.stderr, )