When lefthook-local.yml is present, Lefthook merges its content with lefthook.yml.
- Overriding: You can change properties of existing commands (e.g., changing the
run command or setting skip: true). - Extending: You can add new configuration properties to existing hooks (e.g., setting
parallel: true on a hook) or define entirely new hooks (e.g., adding a post-merge hook).
Example Scenario
Main configuration (lefthook.yml):
pre-commit:
commands:
lint:
run: bundle exec rubocop -- {staged_files}
glob: "*.rb"
check-links:
run: lychee -- {staged_files}
Local overrides (lefthook-local.yml):
pre-commit:
parallel: true
commands:
lint:
run: docker-compose run backend {cmd} # Wraps the original command
check-links:
skip: true # Disables this specific command
post-merge:
files: "git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD"
commands:
dependencies:
glob: "Gemfile*"
run: docker-compose run backend bundle install
Resulting merged configuration:
Lefthook will execute the following logic:
pre-commit:
parallel: true
commands:
lint:
run: docker-compose run backend bundle exec rubocop -- {staged_files}
glob: "*.rb"
check-links:
run: lychee -- {staged_files}
skip: true
post-merge:
files: "git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD"
commands:
dependencies:
glob: "Gemfile*"
run: docker-compose run backend bundle install
# lefthook-local.yml example
pre-commit:
parallel: true
commands:
lint:
run: docker-compose run backend {cmd}
check-links:
skip: true