Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable path to lefthook to run during git hook #653

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Then use git as usually, you don't need to reinstall lefthook when you change th
- [`LEFTHOOK_EXCLUDE`](#lefthook_exclude)
- [`LEFTHOOK_QUIET`](#lefthook_quiet)
- [`LEFTHOOK_VERBOSE`](#lefthook_verbose)
- [`LEFTHOOK_PATH`](#lefthook_path)
- [Features and tips](#features-and-tips)
- [Disable lefthook in CI](#disable-lefthook-in-ci)
- [Local config](#local-config)
Expand Down Expand Up @@ -192,6 +193,15 @@ SUMMARY: (done in 0.01 seconds)

Set `LEFTHOOK_VERBOSE=1` or `LEFTHOOK_VERBOSE=true` to enable verbose printing.

### `LEFTHOOK_PATH`

Set `LEFTHOOK_PATH` to a location where lefthook is installed to use that instead of trying to detect it on the path or your package manager.

Useful for cases when:

- lefthook is installed multiple ways, and you want to be explicit about which one is used (example: installed through homebrew, but also is in Gemfile but you are using a ruby version manager like rbenv that prepends it to the path)
- debugging and/or developing lefthook

## Features and tips

### Disable lefthook in CI
Expand Down
9 changes: 8 additions & 1 deletion internal/templates/hook.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi
Expand All @@ -15,7 +19,10 @@ call_lefthook()
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/')

if lefthook{{.Extension}} -h >/dev/null 2>&1
if test -n "$LEFTHOOK_PATH"
then
"$LEFTHOOK_PATH" "$@"
technicalpickles marked this conversation as resolved.
Show resolved Hide resolved
elif lefthook{{.Extension}} -h >/dev/null 2>&1
then
lefthook{{.Extension}} "$@"
{{if .Extension -}}
Expand Down
Loading