Skip to content

Commit

Permalink
feat: use configurable path to lefthook (LEFTHOOK_BIN) (#653)
Browse files Browse the repository at this point in the history
* turn on trace output in git hook when LEFTHOOK_VERBOSE is set
* add support to giving an explicit path to lefthook in git hook. useful for developing
* Document LEFTHOOK_PATH
* Switch to LEFTHOOK_BIN
  • Loading branch information
technicalpickles authored Mar 5, 2024
1 parent 49da7f3 commit 3024a5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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_BIN`](#lefthook_bin)
- [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_BIN`

Set `LEFTHOOK_BIN` to a location where lefthook is installed to use that instead of trying to detect from the it the PATH or from a 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_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook{{.Extension}} -h >/dev/null 2>&1
then
lefthook{{.Extension}} "$@"
{{if .Extension -}}
Expand Down

0 comments on commit 3024a5b

Please sign in to comment.