Skip to content

Commit a6ca08b

Browse files
committed
Updated hooks to work with windows
1 parent 4f20f28 commit a6ca08b

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

hooks/delegate.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sys
44
import os
5+
import shlex
56

67
from natsort import natsorted
78
import envoy
@@ -32,10 +33,13 @@
3233

3334
BULLET_POINTS = "*-+=#~"
3435

35-
PASS = " ✓ PASS"
36+
if sys.stdout.encoding.lower().startswith('utf-'):
37+
PASS = " ✓ PASS"
38+
FAIL = " ✗ FAIL"
39+
else:
40+
PASS = " / PASS"
41+
FAIL = " x FAIL"
3642
WARN = " ! WARN"
37-
FAIL = " ✗ FAIL"
38-
3943

4044
def bullet(depth):
4145
return BULLET_POINTS[depth % len(BULLET_POINTS)]
@@ -56,6 +60,18 @@ def indent(text, depth):
5660
padding = " " * (depth * 4)
5761
return padding + "\n{0}".format(padding).join(text.split("\n")).rstrip()
5862

63+
def platform_command(path):
64+
if sys.platform.startswith("win"):
65+
with open(path) as file:
66+
part = file.read(2)
67+
if part == "#!":
68+
shebang = shlex.split(file.readline().strip())
69+
if shebang:
70+
shebang.pop(0)
71+
path = path.replace('\\', '/')
72+
shebang.append(path)
73+
return " ".join(shebang)
74+
return path
5975

6076
if __name__ == "__main__":
6177
if colorama:
@@ -100,7 +116,7 @@ def indent(text, depth):
100116
continue
101117
path = os.path.join(subdir, filename)
102118
file_depth = depth + 1
103-
result = envoy.run(path, timeout=2)
119+
result = envoy.run(platform_command(path), timeout=2)
104120
out_depth = file_depth + 1
105121
out = indent(result.std_out, out_depth) if result.std_out else None
106122
err = indent(result.std_err, out_depth) if result.std_err else None

install-hooks.bat

+3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ if not exist ".git" (
66

77
for %%A in (pre-commit post-checkout post-merge) do (
88
mklink "%cd%\.git\hooks\%%A" "%~dp0hooks\delegate.py"
9+
mklink /J "%cd%\.git\hooks\%%A.d" "%~dp0hooks\%%A.d"
910
)
1011

12+
mklink /J "%cd%\.git\hooks\helpers" "%~dp0hooks\helpers"
13+
1114
if %errorlevel%==0 (
1215
echo Installed Unity hooks.
1316
) else (

0 commit comments

Comments
 (0)