diff --git a/cmd/templates.go b/cmd/templates.go index 5540dfe6..a04b66b9 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -4,6 +4,7 @@ import ( "bytes" "embed" "text/template" + "runtime" "github.com/spf13/afero" ) @@ -14,6 +15,7 @@ var templatesFS embed.FS type hookTmplData struct { AutoInstall string HookName string + Extension string } func hookTemplate(hookName string, fs afero.Fs) []byte { @@ -22,6 +24,7 @@ func hookTemplate(hookName string, fs afero.Fs) []byte { err := t.Execute(buf, hookTmplData{ AutoInstall: autoInstall(hookName, fs), HookName: hookName, + Extension: getExtension(), }) check(err) @@ -40,5 +43,13 @@ func autoInstall(hookName string, fs afero.Fs) string { return "" } - return "# lefthook_version: " + configChecksum(fs) + "\n\ncall_lefthook \"lefthook install\"" + return "# lefthook_version: " + configChecksum(fs) + "\n\ncall_lefthook \"install\"" +} + +func getExtension() string { + if (runtime.GOOS == "windows") { + return ".exe" + } else { + return "" + } } diff --git a/cmd/templates/hook.tmpl b/cmd/templates/hook.tmpl index 4648b028..4968cc5d 100644 --- a/cmd/templates/hook.tmpl +++ b/cmd/templates/hook.tmpl @@ -14,19 +14,19 @@ call_lefthook() { if lefthook -h >/dev/null 2>&1 then - eval $1 - elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook" + eval lefthook $1 + elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook{{.Extension}}" then - eval $dir/node_modules/@arkweid/lefthook/bin/$1 + eval "$dir/node_modules/@arkweid/lefthook/bin/lefthook{{.Extension}} $1" elif bundle exec lefthook -h >/dev/null 2>&1 then - bundle exec $1 + bundle exec lefthook $1 elif npx lefthook -h >/dev/null 2>&1 then - npx $1 + npx lefthook $1 elif yarn lefthook -h >/dev/null 2>&1 then - yarn $1 + yarn lefthook $1 else echo "Can't find lefthook in PATH" fi @@ -34,4 +34,4 @@ call_lefthook() {{.AutoInstall}} -call_lefthook "lefthook run {{.HookName}} $@" +call_lefthook "run {{.HookName}} $@" diff --git a/spec/fixtures/pre-commit b/spec/fixtures/pre-commit index 3d435141..921f4ecd 100644 --- a/spec/fixtures/pre-commit +++ b/spec/fixtures/pre-commit @@ -14,19 +14,19 @@ call_lefthook() { if lefthook -h >/dev/null 2>&1 then - eval $1 + eval lefthook $1 elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook" then - eval $dir/node_modules/@arkweid/lefthook/bin/$1 + eval "$dir/node_modules/@arkweid/lefthook/bin/lefthook $1" elif bundle exec lefthook -h >/dev/null 2>&1 then - bundle exec $1 + bundle exec lefthook $1 elif npx lefthook -h >/dev/null 2>&1 then - npx $1 + npx lefthook $1 elif yarn lefthook -h >/dev/null 2>&1 then - yarn $1 + yarn lefthook $1 else echo "Can't find lefthook in PATH" fi @@ -34,4 +34,4 @@ call_lefthook() -call_lefthook "lefthook run pre-commit $@" +call_lefthook "run pre-commit $@" diff --git a/spec/fixtures/pre-push b/spec/fixtures/pre-push index 34d0b46b..4974214a 100644 --- a/spec/fixtures/pre-push +++ b/spec/fixtures/pre-push @@ -14,19 +14,19 @@ call_lefthook() { if lefthook -h >/dev/null 2>&1 then - eval $1 + eval lefthook $1 elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook" then - eval $dir/node_modules/@arkweid/lefthook/bin/$1 + eval "$dir/node_modules/@arkweid/lefthook/bin/lefthook $1" elif bundle exec lefthook -h >/dev/null 2>&1 then - bundle exec $1 + bundle exec lefthook $1 elif npx lefthook -h >/dev/null 2>&1 then - npx $1 + npx lefthook $1 elif yarn lefthook -h >/dev/null 2>&1 then - yarn $1 + yarn lefthook $1 else echo "Can't find lefthook in PATH" fi @@ -34,4 +34,4 @@ call_lefthook() -call_lefthook "lefthook run pre-push $@" +call_lefthook "run pre-push $@"