### Example Lefthook Configuration with Setup
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/setup.md
This example demonstrates how to define `setup` instructions in a `lefthook.yml` file. The setup command installs `golangci-lint` if it's not already present, before running the linter job.
```yaml
# lefthook.yml
pre-commit:
setup:
- run: |
if ! command -v golangci-lint >/dev/null 2>&1;
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1
jobs:
- run: golangci-lint -- {staged_files}
glob: "*.go"
```
--------------------------------
### Initial Git Setup
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/restore_unstaged_on_conflict_with_stage_fixed.txt
Sets up a new Git repository, configures user details, and installs lefthook.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec lefthook install
exec git add -A
exec git commit -m 'initial'
```
--------------------------------
### Basic Lefthook Setup and Execution
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/group_envs.txt
Demonstrates the initial setup of a Git repository and the installation and execution of Lefthook with a test hook.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec lefthook run test
stdout '\s*1\s*3\s*'
```
--------------------------------
### Setup and Initial Commit
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_interrupt.txt
Initializes a Git repository, installs Lefthook, and performs a basic commit to set up the environment.
```bash
chmod 0700 hook.sh
chmod 0700 commit-with-interrupt.sh
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec lefthook install
exec git add -A
exec git commit -m 'init'
stderr 'hook-done'
```
--------------------------------
### Setup and Install Lefthook on Windows
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/timeout_success.txt
Commands to initialize a Git repository, configure user details, add files, and install Lefthook. This sets up the environment for the hook.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec git commit -m 'test' --allow-empty
! stderr 'timeout'
```
--------------------------------
### Lefthook TL;DR Usage
Source: https://github.com/evilmartians/lefthook/blob/master/README.md
Quick start guide for Lefthook. Configure hooks, install them, and start using Git.
```bash
# Configure your hooks
vim lefthook.yml
# Install them to the git project
lefthook install
# Enjoy your work with git
git add -A && git commit -m '...'
```
--------------------------------
### Install and run lefthook hooks
Source: https://github.com/evilmartians/lefthook/wiki/Migration-from-overcommit
After configuring lefthook, install the new hooks and run them to test your setup.
```bash
lefthook install && lefthook run pre-commit
```
--------------------------------
### Test Setup and Execution for Lefthook Filters
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_file_type.txt
This script initializes a git repository, configures user details, installs Lefthook, creates necessary files and symlinks, and then runs Lefthook with filters to verify output.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec lefthook install
chmod 777 executable
symlink symlink -> results
exec git add -A
exec git commit -m 'test'
exec lefthook run filters
stdout '.*all ❯\s+executable lefthook.yml results symlink\s+┃.*'
stdout '.*filter_text ❯\s+executable lefthook.yml results\s+┃.*'
stdout '.*filter_executable ❯\s+executable\s+┃.*'
stdout '.*filter_symlink ❯\s+symlink\s+┃.*'
stdout '.*filter_not_symlink ❯\s+executable lefthook.yml results\s+┃.*'
stdout '.*filter_not_executable ❯\s+lefthook.yml results symlink\s*'
```
--------------------------------
### Git and Lefthook Setup Commands
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_json.txt
These commands initialize a Git repository, configure user details, add all files, install Lefthook, and perform an initial commit. The stderr command checks for Lefthook's output.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec git commit -m 'test'
stderr '\s*Hi there from Lefthook\s*'
```
--------------------------------
### Initialize and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/files_override.txt
Initializes a Git repository and installs Lefthook hooks.
```bash
exec git init
exec lefthook install
exec git add -A
```
--------------------------------
### Install Lefthook as a Go Tool
Source: https://github.com/evilmartians/lefthook/blob/master/README.md
Install Lefthook as a Go tool. This method is an alternative to direct installation.
```bash
go get -tool github.com/evilmartians/lefthook/v2@v2.1.9
```
--------------------------------
### Initialize Git Repository and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/fail_on_changes_recover_previous_change.txt
Sets up a new Git repository, configures user details, adds all files, makes an initial commit, and installs Lefthook.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add .
exec git commit -m "firstcommit"
exec lefthook install
```
--------------------------------
### Install Lefthook on Alpine
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/alpine.md
Installs bash and curl, downloads and executes the Lefthook setup script from Cloudsmith, and finally installs Lefthook.
```sh
sudo apk add --no-cache bash curl
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.alpine.sh' | sudo -E bash
sudo apk add lefthook
```
--------------------------------
### Initialize Git Repository and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_deleted_only.txt
Sets up a Git repository, configures user details, adds all files, commits, and installs Lefthook. This is a prerequisite for running the tests.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git commit -m 'initial'
exec lefthook install
```
--------------------------------
### Install Commitlint and Commitizen Dependencies
Source: https://github.com/evilmartians/lefthook/blob/master/examples/commitlint/README.md
Install Commitlint CLI and conventional config. Optionally install Commitizen and its conventional changelog adapter.
```bash
yarn add -D @commitlint/cli @commitlint/config-conventional
# If using commitzen
yarn add -D commitizen cz-conventional-changelog
```
--------------------------------
### Initialize Git and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/cli_run_only.txt
Sets up a Git repository and installs Lefthook as a pre-commit hook. This is a prerequisite for running Lefthook commands.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
```
--------------------------------
### Initialize Git and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/env_overwrite_issue_1137.txt
Initializes a Git repository, configures user details, adds all files, and installs Lefthook. Finally, it runs Lefthook hooks.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec lefthook run test
```
--------------------------------
### Initialize Git and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/exclude.txt
This snippet shows the initial steps to set up a Git repository and install Lefthook. It configures Git user details before running Lefthook commands.
```bash
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
```
--------------------------------
### Initializing and Installing Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_script_with_args.txt
Initializes a Git repository, configures user details, adds all files, and installs Lefthook. This is a prerequisite for running Lefthook commands.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec git commit -m 'test'
stderr '\s*Args: lefthook.yml\s*'
```
--------------------------------
### Initialize Git and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/job_stage_fixed.txt
Initializes a Git repository and installs Lefthook. This is a prerequisite for running Lefthook hooks.
```bash
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
```
--------------------------------
### Initialize and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/lefthook_option.txt
Initializes a Git repository and installs Lefthook. This is a foundational step for using Lefthook in a project.
```bash
exec git init
exec lefthook install
```
--------------------------------
### Initialize and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/stage_fixed.txt
Initializes a Git repository and installs Lefthook. This is a prerequisite for using Lefthook features.
```bash
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git status --short
exec git commit -m 'test stage_fixed'
exec git status --short
! stdout .
```
--------------------------------
### Install lefthook
Source: https://github.com/evilmartians/lefthook/wiki/Migration-from-overcommit
Install lefthook using RubyGems and then initialize it in your project.
```bash
gem install lefthook && lefthook install
```
--------------------------------
### Lefthook Integration Test Setup and Assertion
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/job_fail_text.txt
This snippet shows the shell commands used in an integration test to set up a Git repository, install Lefthook, and then execute a commit that triggers the failing pre-commit hook. It asserts that the stderr output matches the expected failure pattern.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
! exec git commit -m 'test'
stderr '\s*fails: no such command\s*'
```
--------------------------------
### Basic Run Command Example
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/run.md
Example of a simple 'run' command for the 'pre-commit' hook to execute 'yarn lint'.
```yaml
# lefthook.yml
pre-commit:
commands:
lint:
run: yarn lint
```
--------------------------------
### Example Folder Structure
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/root.md
Illustrates a typical project structure where 'root' might be used to target a specific sub-directory.
```bash
# Folders structure
$ tree .
.
├── client/
│ ├── package.json
│ ├── node_modules/
| ├── ...
├── server/
| ...
```
--------------------------------
### Install RPM Repository and Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/rpm.md
Installs the Lefthook RPM repository using a script and then installs the lefthook package using yum.
```sh
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.rpm.sh' | sudo -E bash
sudo yum install lefthook
```
--------------------------------
### Main Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/features/local.md
This is an example of a main `lefthook.yml` configuration file that defines jobs for pre-commit hooks.
```yaml
# lefthook.yml (committed into your repo)
pre-commit:
jobs:
- name: linter
run: yarn lint
- name: tests
run: yarn test
```
--------------------------------
### Initialize Git Repository and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/restore_unstaged.txt
Initializes a Git repository, configures user details, and installs Lefthook. This sets up the basic environment for testing hook functionality.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec lefthook install
```
--------------------------------
### Initialize Git Repository and Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_script.txt
This sequence of commands initializes a Git repository, sets up user email and name, stages all files, installs Lefthook, and makes an initial commit. It's used to set up the environment for Lefthook pre-commit hooks.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec git commit -m 'test'
stderr '\s*Hi there from script\s*'
```
--------------------------------
### Install legacy @evilmartians/lefthook-installer with npm
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/node.md
Install the legacy '@evilmartians/lefthook-installer' package, which fetches the correct executable during installation.
```bash
npm install --save-dev @evilmartians/lefthook-installer
```
--------------------------------
### Lefthook Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/job_merging.txt
Demonstrates a basic Lefthook configuration with job merging and inheritance.
```yaml
---
extends:
- extends/e1.yml
pre-commit:
jobs:
- name: group
group:
jobs:
- name: child
run: named
- run: 0 no-name
- name: echo
run: echo 0
- run: lefthook.yml
```
--------------------------------
### Sample 'executable' file content
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_file_type.txt
This is the content of the 'executable' file used in the test setup, marked as executable.
```shell
-- executable --
#!/bin/sh
echo 'Executable'
```
--------------------------------
### Install Lefthook and Push to Remote
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/pre_push_sha256_initial.txt
Installs Lefthook and performs the initial push to the configured remote repository. This step ensures hooks are active and code is synchronized.
```bash
exec lefthook install
exec git push -u origin main
```
--------------------------------
### Enable Lefthook Installation in CI
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/envs/LEFTHOOK.md
When CI=true, use LEFTHOOK=1 or LEFTHOOK=true to ensure hooks are installed during package installation.
```bash
LEFTHOOK=1 npm install
```
```bash
LEFTHOOK=1 yarn install
```
```bash
LEFTHOOK=1 pnpm install
```
--------------------------------
### Install Lefthook
Source: https://github.com/evilmartians/lefthook/wiki/Migration-from-husky
Installs Lefthook as a development dependency.
```bash
npm install @arkweid/lefthook --save-dev
```
--------------------------------
### Install Lefthook with Pipx
Source: https://github.com/evilmartians/lefthook/blob/master/README.md
Install Lefthook using Pipx for Python projects.
```bash
pipx install lefthook
```
--------------------------------
### Install Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/check_install.txt
Installs Lefthook into the Git repository. This command should be run after initializing Git and staging files.
```bash
exec lefthook install
```
--------------------------------
### Example Text File
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/lefthook_option.txt
A sample text file used in conjunction with Lefthook configurations.
```text
sometext
```
--------------------------------
### Initialize Lefthook and Commit
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/setup_instructions.txt
Commands to initialize Git, configure user details, add all files, install Lefthook, and make an initial commit.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec git commit -m 'test'
stderr '\s*Setup 1\s*Setup 2\s*Hi there from Lefthook\s*'
```
--------------------------------
### Install Lefthook as Global Go Package
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/go.md
Use this command to install Lefthook as a global package for your Go environment. Ensure you have Go version 1.26 or higher installed.
```bash
go install github.com/evilmartians/lefthook/v2@v2.1.9
```
--------------------------------
### Add Lefthook Repository and Install
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/deb.md
Use this command to add the Lefthook APT repository to your system and then install the lefthook package. This is the primary method for Debian/Ubuntu installations.
```sh
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.deb.sh' | sudo -E bash
sudo apt install lefthook
```
--------------------------------
### Install Lefthook with npm
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/node.md
Use this command to install the main 'lefthook' package using npm.
```bash
npm install --save-dev lefthook
```
--------------------------------
### Install Lefthook with NPM
Source: https://github.com/evilmartians/lefthook/blob/master/README.md
Install Lefthook as a development dependency using NPM.
```bash
npm install lefthook --save-dev
```
--------------------------------
### Example File Content
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/exclude_arg.txt
These are example file contents used in the exclusion tests. 'file1.txt' contains 'Hello' and 'file2.txt' contains 'Hi'.
```text
-- file1.txt --
Hello
```
```text
-- file2.txt --
Hi
```
--------------------------------
### HTML File Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_mime_type.txt
An example HTML file. Lefthook can be configured to run specific commands when files with the 'text/html' MIME type are modified.
```html
-- html --
Hello
```
--------------------------------
### Install Lefthook with yarn
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/node.md
Use this command to install the main 'lefthook' package using yarn.
```bash
yarn add --dev lefthook
```
--------------------------------
### Example File Content
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/stage_fixed_505.txt
Content of an example JavaScript file that might be modified by the Lefthook configuration.
```javascript
-- [file].js --
somecode
```
--------------------------------
### Example Remote Configuration
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/remotes.md
This example shows how to define a remote configuration in your `lefthook.yml` file. It specifies the Git URL, a reference (like a tag or branch), and the path to the configuration file within the remote repository.
```yaml
# lefthook.yml
remotes:
- git_url: git@github.com:evilmartians/lefthook
ref: v1.0.0
configs:
- examples/ruby-linter.yml
```
--------------------------------
### Lefthook Integration Test Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/templates.txt
An example demonstrating how to integrate Lefthook templates into an integration test. It initializes git, runs a Lefthook command, and asserts the output.
```shell
exec git init
exec lefthook run test
stdout '^ *hello *$ '
```
--------------------------------
### Install Commitlint and Commitizen Dependencies
Source: https://github.com/evilmartians/lefthook/blob/master/docs/examples/commitlint.md
Install the necessary packages for Commitlint and Commitizen using Yarn.
```bash
yarn add -D @commitlint/cli @commitlint/config-conventional
# For commitzen
yarn add -D commitizen cz-conventional-changelog
```
--------------------------------
### Initialize Git Repository
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/install_reset_hooks_path_issue_1429.txt
Initializes a new Git repository. This is a prerequisite for installing Git hooks.
```bash
exec git init
```
--------------------------------
### Install Lefthook from AUR (Pre-compiled Binaries)
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/arch.md
Use this command with yay to install the lefthook-bin package for pre-compiled binaries.
```shell
yay -S lefthook-bin
```
--------------------------------
### Sample 'results' file content
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_file_type.txt
This is the content of the 'results' file used in the test setup.
```text
-- results --
some text
```
--------------------------------
### Install Lefthook from AUR (Compile from Source)
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/arch.md
Use this command with yay to install the lefthook package, which compiles from source.
```shell
yay -S lefthook
```
--------------------------------
### Install Lefthook with Ruby Gem
Source: https://github.com/evilmartians/lefthook/blob/master/README.md
Install Lefthook using the Ruby gem command.
```bash
gem install lefthook
```
--------------------------------
### Example File Content
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/pre-commit_issue_919.txt
This is the content of a file that will be deleted during the pre-commit process.
```text
will be deleted
```
--------------------------------
### Dumped Lefthook Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/remotes.txt
An example of a dumped lefthook configuration, showing pre-commit and pre-push hooks.
```yaml
pre-commit:
parallel: true
commands:
js-lint:
run: npx eslint --fix -- {staged_files} && git add -- {staged_files}
glob:
- '*.{js,ts}'
ping:
run: echo pong
ruby-lint:
run: bundle exec rubocop --force-exclusion --parallel -- '{files}'
files: git diff-tree -r --name-only --diff-filter=CDMR HEAD origin/master
glob:
- '*.rb'
ruby-test:
run: bundle exec rspec
fail_text: Run bundle install
skip:
- merge
- rebase
scripts:
good_job.js:
runner: node
pre-push:
commands:
spelling:
run: npx yaspeller -- {files}
files: git diff --name-only HEAD @{push}
glob:
- '*.md'
remotes:
- git_url: https://github.com/evilmartians/lefthook
ref: v1.4.0
configs:
- examples/with_scripts/lefthook.yml
- git_url: https://github.com/evilmartians/lefthook
configs:
- examples/verbose/lefthook.yml
- examples/remote/ping.yml
```
--------------------------------
### Install Git Hook
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/commands/run.md
Installs the Git hook managed by lefthook. This command must be run before hooks can be triggered.
```bash
$ lefthook install
```
--------------------------------
### Configuring environment variables in .lefthookrc
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/rc.md
Example of a ~/.lefthookrc file demonstrating how to set NVM_DIR and source nvm.sh, or fnm.sh.
```bash
# ~/.lefthookrc
# An nvm way
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# An fnm way
export FNM_DIR="$HOME/.fnm"
[ -s "$FNM_DIR/fnm.sh" ] && \. "$FNM_DIR/fnm.sh"
# Or maybe just
PATH=$PATH:$HOME/.nvm/versions/node/v15.14.0/bin
```
--------------------------------
### Example JavaScript File
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/lefthook_option.txt
A sample JavaScript file, potentially used for testing or as part of the project.
```javascript
somecode
```
--------------------------------
### Install Lefthook for Specific Hooks
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/install_specific.txt
Installs Lefthook for the 'pre-commit' and 'post-commit' Git hooks. This command should be run after initializing the Git repository.
```bash
exec lefthook install pre-commit post-commit
```
--------------------------------
### Install Lefthook with pip
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/python.md
Install Lefthook using pip for the current user. Ensure pip is available and up-to-date.
```sh
python -m pip install --user lefthook
```
--------------------------------
### Initialize and Configure Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/hide_unstaged.txt
Sets up a new Git repository, installs Lefthook, and configures user email and name. This is a prerequisite for using Lefthook's features.
```bash
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git commit -m 'initial commit'
```
--------------------------------
### Install Lefthook Globally
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/ruby.md
Install Lefthook globally using the gem command. This is an alternative to adding it to your Gemfile.
```bash
gem install lefthook
```
--------------------------------
### Install Lefthook with pnpm
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/node.md
Use this command to install the main 'lefthook' package using pnpm. Ensure pnpm-workspace.yaml and pnpm.onlyBuiltDependencies are updated for the postinstall script to execute.
```bash
pnpm add -D lefthook
```
--------------------------------
### Lefthook Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/install_specific.txt
A sample 'lefthook.yml' file defining jobs for 'pre-commit', 'post-commit', and 'pre-push' hooks. Each hook is configured to run a simple 'echo' command.
```yaml
---
pre-commit:
jobs:
- run: echo
post-commit:
jobs:
- run: echo
pre-push:
jobs:
- run: echo
```
--------------------------------
### Lua Script Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_mime_type.txt
A basic Lua script that prints 'Hello'. This script is included in the Lefthook configuration to be run for 'text/x-lua' files.
```lua
-- lua-script --
#!/usr/bin/env lua
print("Hello")
```
--------------------------------
### Example Usage of LEFTHOOK_OUTPUT
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/envs/LEFTHOOK_OUTPUT.md
This example demonstrates how to use the LEFTHOOK_OUTPUT environment variable to display only the summary of Lefthook's execution. It shows the command to run and the expected output.
```bash
$ LEFTHOOK_OUTPUT=summary lefthook run pre-commit
summary: (done in 0.52 seconds)
✔️ lint
```
--------------------------------
### Initialize Git Repository
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/skip_merge_commit.txt
Sets up a new Git repository and configures user information.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git commit -m 'commit 1'
exec lefthook install
```
--------------------------------
### Lefthook Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_yml.txt
This is a sample `lefthook.yml` configuration file. It defines an output setting and a pre-commit hook that runs an echo command.
```yaml
-- lefthook.yml --
output:
- execution_out
pre-commit:
commands:
echo:
run: echo Hi there from Lefthook
```
--------------------------------
### Initialize Git Repository
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/fail_on_changes_issue_1125.txt
Sets up a new Git repository and configures user information.
```bash
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add .
exec git commit -m "firstcommit"
```
--------------------------------
### Shell Script Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_mime_type.txt
A basic shell script that prints 'Hello'. This script can be executed by Lefthook when its file type is matched.
```shell
-- shell-script --
#!/bin/sh
echo 'Hello'
```
--------------------------------
### Example Bash Script for Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/script.md
A simple bash script that can be executed by Lefthook. This example prints a success message.
```bash
# .lefthook/pre-commit/linter.sh
echo "Everything is OK"
```
--------------------------------
### Local Configuration Override Example
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/features/local.md
This example demonstrates a `lefthook-local.yml` file used to override or extend the main configuration, allowing specific jobs to be skipped or modified.
```yaml
# lefthook-local.yml (ignored by git)
pre-commit:
jobs:
- name: tests
skip: true # don't want to run tests on every commit
- name: linter
run: yarn lint {staged_files} # lint only staged files
```
--------------------------------
### Merged Lefthook Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/docs/examples/lefthook-local.md
Illustrates the final configuration that Lefthook will use after merging `lefthook.yml` and `lefthook-local.yml`.
```yml
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
```
--------------------------------
### Install Lefthook Hooks
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/install_reset_hooks_path_issue_1429.txt
Installs Lefthook Git hooks. The '!' prefix indicates that this command is expected to fail or produce stderr output in the context of the issue.
```bash
! exec lefthook install
```
--------------------------------
### Initialize and Configure Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/lefthook_job_name_issue_1345.txt
These commands initialize a Git repository, install Lefthook, and configure Git user details. This is a prerequisite for running Lefthook commands.
```bash
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git commit -m 'test'
stderr 'Macbeth'
```
--------------------------------
### Install Lefthook as Go Tool
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/go.md
Install Lefthook as a Go tool within your project. This method is suitable for managing Lefthook as a project-specific dependency. Requires Go version 1.26 or higher.
```bash
go get -tool github.com/evilmartians/lefthook/v2
```
--------------------------------
### Example Directory Structure
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/source_dir.md
This illustrates the expected directory structure when using a custom source_dir. Each hook type has its own subdirectory containing the relevant scripts.
```directory structure
.lefthook/
├── pre-commit/
│ ├── lint.sh
│ └── test.py
└── pre-push/
└── check-files.rb
```
--------------------------------
### Using {files} Template
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/run.md
Demonstrates running 'go vet' on files identified by 'git ls-files -m' with a '.go' extension using the {files} template.
```yaml
# lefthook.yml
pre-commit:
commands:
govet:
files: git ls-files -m
glob: "*.go"
run: go vet -- {files}
```
--------------------------------
### Initialize Git Repository and Commit
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/pre-commit_issue_919.txt
These commands initialize a Git repository, configure user details, add all files, and make the first commit.
```bash
exec git init
exec git add -A
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git commit -m 'first commit'
```
--------------------------------
### Verify Lefthook Installation
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/check_install.txt
Checks if Lefthook is installed correctly in the current Git repository. This command can be run before and after installation.
```bash
! exec lefthook check-install
```
```bash
exec lefthook check-install
```
--------------------------------
### Multiple Remote Configurations
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/configs.md
Example demonstrating how to merge configurations from multiple remote Git repositories, each potentially specifying different branches or tags and a list of configuration files.
```yml
# lefthook.yml
remotes:
- git_url: git@github.com:org/lefthook-configs
ref: v1.0.0
configs:
- examples/ruby-linter.yml
- examples/test.yml
- git_url: https://github.com/org2/lefthook-configs
configs:
- lefthooks/pre_commit.yml
- lefthooks/post_merge.yml
- git_url: https://github.com/org3/lefthook-configs
ref: feature/new
configs:
- configs/pre-push.yml
```
--------------------------------
### Example of Filtered Command Execution
Source: https://github.com/evilmartians/lefthook/blob/master/docs/examples/filters.md
This example demonstrates the final command executed after filters are applied. It shows that only 'frontend/src/index.ts' is passed to the 'lint' command, based on the filters defined in the configuration.
```bash
yarn lint frontend/src/index.ts --fix
```
--------------------------------
### Dump.yml Output Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/job_merging.txt
Shows the expected output of 'lefthook dump' command, illustrating the merged configuration.
```yaml
---
e1:
jobs:
- name: echo
run: e1
e2:
jobs:
- name: echo
run: e2
e3:
jobs:
- name: echo
run: e3
extends:
- extends/e1.yml
pre-commit:
jobs:
- name: group
glob:
- '*.rb'
group:
jobs:
- name: child
run: child named with glob
stage_fixed: true
- run: 0 no-name
- run: 1 no-name
- run: 2 no-name
- run: 3 no-name
- name: echo
run: echo 2
glob:
- "3"
tags:
- backend
skip: true
- run: lefthook.yml
- run: e1
- run: e2
- run: e3
```
--------------------------------
### Install Lefthook using pip
Source: https://github.com/evilmartians/lefthook/blob/master/packaging/registries/pypi/README.md
Install the Lefthook package using pip. This is the primary method for installing Lefthook.
```bash
pip install lefthook
```
--------------------------------
### Add a Git Hook with Directory Creation
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/commands/add.md
Installs the `pre-push` hook and creates the necessary directory structure if it doesn't exist. Use this command before configuring hook scripts.
```bash
$ lefthook add pre-push --dirs
```
--------------------------------
### Lefthook Timeout Configuration Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/timeout.txt
This example shows how to configure a 'slow' command in `lefthook.yml` with a timeout of 100 milliseconds. The `sleep 10` command is intended to exceed this timeout, demonstrating the timeout functionality.
```yaml
-- lefthook.yml --
output:
- failure
pre-commit:
commands:
slow:
timeout: 100ms
run: sleep 10
```
--------------------------------
### Example Lefthook Configuration
Source: https://github.com/evilmartians/lefthook/blob/master/docs/index.md
This configuration runs linters on the `pre-commit` hook. It utilizes parallel execution for faster linting and specifies glob patterns for different file types.
```yml
# lefthook.yml
pre-commit:
parallel: true
jobs:
- run: yarn run stylelint --fix '{staged_files}'
glob: "*.css"
stage_fixed: true
- run: yarn run eslint --fix '{staged_files}'
glob:
- "*.ts"
- "*.js"
- "*.tsx"
- "*.jsx"
stage_fixed: true
```
--------------------------------
### Husky Configuration in package.json
Source: https://github.com/evilmartians/lefthook/wiki/Migration-from-husky-with-lint-staged
Example of Git hook configuration using Husky within `package.json`.
```json
// package.json
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": "eslint"
}
}
```
--------------------------------
### Run Lefthook Swift Plugin with Mint
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/swift.md
Execute the Lefthook Swift wrapper plugin using the Mint version manager. Ensure Mint is installed and configured.
```bash
mint run csjones/lefthook-plugin
```
--------------------------------
### Python Script Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_mime_type.txt
A standard Python script that outputs 'Hello'. Lefthook can trigger this script if the changed file has the 'text/x-python' MIME type.
```python
-- python-script --
#!/usr/bin/env python
if __name__ == '__main__':
print("Hello")
```
--------------------------------
### Lefthook Configuration (YAML)
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/dump.txt
Example of a Lefthook configuration file in YAML format. This defines colors, pre-commit hooks, and scripts.
```yaml
colors:
cyan: 14
gray: 244
green: '#32CD32'
red: '#FF1493'
yellow: '#F0E68C'
pre-commit:
follow: true
commands:
lint:
interactive: true
skip:
- merge
- rebase
- ref: main
run: yarn lint {staged_files}
test:
skip: merge
glob: "*.js"
run: yarn test
scripts:
"my-script.sh":
runner: bash
use_stdin: true
stage_fixed: true
env:
FOO: bar
```
--------------------------------
### Lefthook Configuration in lefthook.yml
Source: https://github.com/evilmartians/lefthook/wiki/Migration-from-husky
Example of equivalent Git hook configuration for Lefthook in `lefthook.yml`.
```yaml
# lefthook.yml
pre-commit:
commands:
sometest:
run: npm test
pre-push:
commands:
anothertest:
run: npm test
```
--------------------------------
### Perl Script Example
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/filter_by_mime_type.txt
A simple Perl script that prints 'Hello'. This script is intended to be run by Lefthook when the 'text/x-perl' MIME type is detected.
```perl
-- perl-script --
#!/usr/bin/env perl
say 'Hello'
```
--------------------------------
### Install Git Hooks
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage.md
Use this command to create or update Git hooks based on your lefthook.yml configuration. If no configuration file exists, it creates an empty one.
```bash
lefthook install
```
--------------------------------
### Using {push_files} Template
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/run.md
Example of running 'yarn eslint' on files that are committed but not yet pushed using the {push_files} template for the 'pre-push' hook.
```yaml
# lefthook.yml
pre-push:
commands:
eslint:
glob: "*.{js,ts,jsx,tsx}"
run: yarn eslint {push_files}
```
--------------------------------
### Run Lefthook with Different Command-Line Exclusion
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/exclude_arg.txt
This example demonstrates excluding 'file2.txt' from the 'test' command, showing the flexibility of the --exclude argument.
```bash
exec lefthook run test --exclude file2.txt
stdout '\s*file1.txt\s*file1.txt\s*'
```
--------------------------------
### Prevent Lefthook Installation in CI
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/envs/CI.md
Set CI=true when installing Lefthook via NPM, Yarn, or PNPM to prevent the automatic installation of hooks during the postinstall script. This is useful for CI environments where hooks are not needed.
```bash
CI=true npm install
```
```bash
CI=true yarn install
```
```bash
CI=true pnpm install
```
--------------------------------
### Local Skip Override Example
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/skip.md
Demonstrates how to use a local configuration file (`lefthook-local.yml`) to override the `skip` option for specific commands, effectively disabling them locally.
```yaml
# lefthook.yml
pre-commit:
commands:
lint:
run: yarn lint
```
```yaml
# lefthook-local.yml
pre-commit:
commands:
lint:
skip: true
```
--------------------------------
### Define Commands for a Hook
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/Commands.md
Example of how to specify commands for the 'pre-commit' hook in the lefthook.yml configuration file. This sets up a 'lint' command with further options.
```yaml
# lefthook.yml
pre-commit:
commands:
lint:
... # command options
```
--------------------------------
### Disable Automatic Git Hook Installation
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/no_auto_install.md
Set `no_auto_install` to `true` in your `lefthook.yml` to prevent lefthook from automatically installing or updating git hooks when the configuration is modified. This is useful if you want to manually manage hook installations.
```yaml
no_auto_install: true
pre-commit:
commands:
lint:
run: npm run lint
```
--------------------------------
### Single Remote Configuration
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/configs.md
Example of a `lefthook.yml` file specifying a single remote Git URL and a list of configuration files to be included from that remote.
```yml
# lefthook.yml
remotes:
- git_url: git@github.com:evilmartians/lefthook
ref: v1.0.0
configs:
- examples/ruby-linter.yml
- examples/test.yml
```
--------------------------------
### Configure pre-push Hook in lefthook.yml
Source: https://github.com/evilmartians/lefthook/blob/master/docs/usage/commands/add.md
Defines the commands to be executed by the `pre-push` hook. This example specifies running an `audit.sh` script using a bash runner.
```yaml
pre-push:
jobs:
- script: "audit.sh"
runner: bash
```
--------------------------------
### Enable fail_on_changes_diff
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/fail_on_changes_diff.md
This example shows how to explicitly enable diff output when fail_on_changes is triggered, regardless of the environment. This configuration is placed within the lefthook.yml file.
```yaml
# lefthook.yml
pre-commit:
parallel: true
fail_on_changes: "always"
fail_on_changes_diff: true
commands:
lint:
run: yarn lint
test:
run: yarn test
```
--------------------------------
### Configure Lefthook Output Verbosity
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/output.md
Specify which types of output Lefthook should display. This example shows how to enable meta, summary, empty_summary, success, failure, execution, execution_out, execution_info, and skips.
```yaml
# lefthook.yml
output:
- meta # Print lefthook version
- summary # Print summary block (successful and failed steps)
- empty_summary # Print summary heading when there are no steps to run
- success # Print successful steps
- failure # Print failed steps printing
- execution # Print any execution logs
- execution_out # Print execution output
- execution_info # Print `EXECUTE > ...` logging
- skips # Print "skip" (i.e. no files matched)
```
--------------------------------
### Install legacy @evilmartians/lefthook with npm
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/node.md
Install the legacy '@evilmartians/lefthook' package, which provides executables for all operating systems.
```bash
npm install --save-dev @evilmartians/lefthook
```
--------------------------------
### Configure Command and Script Priority
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/priority.md
This example demonstrates setting priorities for both commands and scripts within a `post-checkout` hook. Commands and scripts with higher priority values will execute first. Note that `priority: 0` is treated as +Infinity and runs last.
```yaml
# lefthook.yml
post-checkout:
piped: true
commands:
db-create:
priority: 1
run: rails db:create
db-migrate:
priority: 2
run: rails db:migrate
db-seed:
priority: 3
run: rails db:seed
scripts:
"check-spelling.sh":
runner: bash
priority: 1
"check-grammar.rb":
runner: ruby
priority: 2
```
--------------------------------
### Initialize Git Repository
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/job_merging.txt
Command to initialize a new Git repository. This is a prerequisite for using Lefthook.
```bash
exec git init
```
--------------------------------
### Initial State of `a.txt`
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/restore_unstaged_on_conflict_with_stage_fixed.txt
Shows the content of `a.txt` before the conflict scenario is initiated.
```text
line1
line2
line3
```
--------------------------------
### Initial State of `b.txt`
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/restore_unstaged_on_conflict_with_stage_fixed.txt
Shows the content of `b.txt` before the conflict scenario is initiated.
```text
line1
lineCommitted
line3
```
--------------------------------
### Install Latest Lefthook with Mise
Source: https://github.com/evilmartians/lefthook/blob/master/docs/installation/mise.md
Use this command to install the latest version of Lefthook via Mise. The Mise plugin for Lefthook is community-maintained.
```bash
mise use lefthook@latest
```
--------------------------------
### Configure Commitlint
Source: https://github.com/evilmartians/lefthook/blob/master/docs/examples/commitlint.md
Set up the Commitlint configuration file using the conventional changelog configuration.
```javascript
// commitlint.config.js
module.exports = {extends: ['@commitlint/config-conventional']};
```
--------------------------------
### Installing Lefthook git hooks
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/rc.md
Command to install Lefthook git hooks after updating the configuration. This is an important step to ensure changes are applied.
```bash
# Make sure you updated git hooks. This is important.
$ lefthook install -f
```
--------------------------------
### Build and Test Commands
Source: https://github.com/evilmartians/lefthook/blob/master/AGENTS.md
Common make commands for building, testing, linting, and regenerating JSON schema for the project.
```bash
make build # compile
make test # unit tests
make test-integration # integration tests
make lint # golangci-lint
make jsonschema # regenerate schema.json after config changes
```
--------------------------------
### Set up Bare Remote Repository
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/pre_push_sha256_initial.txt
Creates a bare Git repository and adds it as a remote. This is essential for pushing code to a central location.
```bash
exec git init --bare --object-format=sha256 ../remote.git
exec git remote add origin ../remote.git
```
--------------------------------
### Running pre-commit
Source: https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-pre-commit
Command to execute all configured pre-commit hooks.
```bash
pre-commit run
```
--------------------------------
### Sample File Content 1.txt
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/sh_syntax_in_files.txt
Content of the sample file '1.txt'.
```text
-- 1.txt --
1.txt
```
--------------------------------
### Reset Lefthook Hooks Path
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/install_reset_hooks_path_issue_1429.txt
Installs Lefthook and explicitly resets the Git hooks path to the default location. This is the recommended command to resolve path-related installation issues.
```bash
exec lefthook install --reset-hooks-path
```
--------------------------------
### Initialize Git Repository
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/check_install.txt
Initializes a new Git repository. This is a prerequisite for Lefthook to function.
```bash
exec git init
```
--------------------------------
### Using args for Staged Files
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/args.md
This example demonstrates how to use the `args` option to pass staged files to a bash script and a yarn command. It shows how to specify glob patterns to limit the files processed by each job.
```yaml
# lefthook.yml
pre-commit:
jobs:
- script: check-python-files.sh
runner: bash
args: "{staged_files}"
glob: "*.py"
- run: yarn lint
args: "{staged_files}"
glob:
- "*.ts"
- "*.js"
```
--------------------------------
### Example of fail_text output
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/fail_text.md
This example demonstrates the output when a commit fails and the `fail_text` is triggered. The custom message 'Add node executable to $PATH env' is appended to the command's failure summary.
```bash
$ git commit -m 'fix: Some bug'
Lefthook v1.1.3
RUNNING HOOK: pre-commit
EXECUTE > lint
SUMMARY: (done in 0.01 seconds)
🥊 lint: Add node executable to $PATH env
```
--------------------------------
### Sample File Content 20.txt
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/sh_syntax_in_files.txt
Content of the sample file '20.txt'.
```text
-- 20.txt --
20.txt
```
--------------------------------
### Initial Content of b.txt
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/restore_unstaged.txt
Shows the initial content of the file 'b.txt' before any hook modifications.
```text
-- b.txt --
lineCommitted
```
--------------------------------
### Create and Commit Second File
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/skip_merge_commit.txt
Checks out the previous branch, creates a new file, and commits it.
```bash
exec git checkout -
exec touch file.B
exec git add -A
exec git commit -m 'commit B'
```
--------------------------------
### Sample File Content 10.txt
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/sh_syntax_in_files.txt
Content of the sample file '10.txt'.
```text
-- 10.txt --
10.txt
```
--------------------------------
### Verify Pre-commit Hook Existence
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/install_reset_hooks_path_issue_1429.txt
Checks if the pre-commit hook file exists in the .git/hooks directory after installation.
```bash
exists .git/hooks/pre-commit
```
--------------------------------
### Update Lefthook Binary
Source: https://github.com/evilmartians/lefthook/blob/master/docs/install.md
Use this command to update the Lefthook binary to the latest version when installed manually.
```bash
lefthook self-update
```
--------------------------------
### Initial Content of a.txt
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/restore_unstaged.txt
Shows the initial content of the file 'a.txt' before any hook modifications.
```text
-- a.txt --
line
```
--------------------------------
### Extending Lefthook Configuration
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/extends.md
This example shows how to use the `extends` option in `lefthook.yml` to include configurations from various local and remote YAML files. It demonstrates the use of direct paths, relative paths, and glob patterns for dynamic inclusion.
```yaml
# lefthook.yml
extends:
- /home/user/work/lefthook-extend.yml
- /home/user/work/lefthook-extend-2.yml
- lefthook-extends/file.yml
- ../extend.yml
- projects/*/specific-lefthook-config.yml
```
--------------------------------
### Configure Script Execution in Lefthook
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/script.md
Example of defining a script to be executed by Lefthook. Specify the script name and the runner.
```yaml
# lefthook.yml
pre-commit:
jobs:
- script: linter.sh
runner: bash
```
--------------------------------
### Run Existing Hook
Source: https://github.com/evilmartians/lefthook/blob/master/tests/integration/run_non_existing.txt
Executes a predefined 'pre-commit' hook. This is a standard operation.
```bash
exec lefthook run pre-commit
```
--------------------------------
### Lefthook configuration with npm script
Source: https://github.com/evilmartians/lefthook/blob/master/docs/configuration/rc.md
Example of a lefthook.yml file that uses an npm script for linting staged files.
```yaml
# lefthook.yml
pre-commit:
commands:
lint:
run: npm run eslint {staged_files}
```