Skip to content

Commit

Permalink
Fix lefthook binary extension on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed May 15, 2021
1 parent ecc4670 commit d0e8d2e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
13 changes: 12 additions & 1 deletion cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"embed"
"text/template"
"runtime"

"github.com/spf13/afero"
)
Expand All @@ -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 {
Expand All @@ -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)

Expand All @@ -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 ""
}
}
14 changes: 7 additions & 7 deletions cmd/templates/hook.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ 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
}

{{.AutoInstall}}

call_lefthook "lefthook run {{.HookName}} $@"
call_lefthook "run {{.HookName}} $@"
12 changes: 6 additions & 6 deletions spec/fixtures/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ 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
}



call_lefthook "lefthook run pre-commit $@"
call_lefthook "run pre-commit $@"
12 changes: 6 additions & 6 deletions spec/fixtures/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ 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
}



call_lefthook "lefthook run pre-push $@"
call_lefthook "run pre-push $@"

0 comments on commit d0e8d2e

Please sign in to comment.