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 505f9bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ 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 \"lefthook\" \"install\""
}
19 changes: 12 additions & 7 deletions cmd/templates/hook.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,33 @@ fi

dir="$(cd "$(dirname "$(dirname "$(dirname "$0")")")" >/dev/null 2>&1 || exit ; pwd -P)"

extension=""
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
extension=".exe"
fi

call_lefthook()
{
if lefthook -h >/dev/null 2>&1
then
eval $1
elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook"
eval "$1 $2"
elif test -f "$dir/node_modules/@arkweid/lefthook/bin/$1$extension"
then
eval $dir/node_modules/@arkweid/lefthook/bin/$1
eval "$dir/node_modules/@arkweid/lefthook/bin/$1$extension $2"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec $1
bundle exec "$1 $2"
elif npx lefthook -h >/dev/null 2>&1
then
npx $1
npx "$1 $2"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn $1
yarn "$1 $2"
else
echo "Can't find lefthook in PATH"
fi
}

{{.AutoInstall}}

call_lefthook "lefthook run {{.HookName}} $@"
call_lefthook "lefthook" "run {{.HookName}} $@"

0 comments on commit 505f9bb

Please sign in to comment.