Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akr4/git-hooks-dispatch
Run hooks only in a directory where files are changed. Useful for monorepo.
https://github.com/akr4/git-hooks-dispatch
Last synced: about 1 month ago
JSON representation
Run hooks only in a directory where files are changed. Useful for monorepo.
- Host: GitHub
- URL: https://github.com/akr4/git-hooks-dispatch
- Owner: akr4
- License: mit
- Created: 2021-07-31T07:40:35.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2021-09-08T04:13:42.000Z (about 3 years ago)
- Last Synced: 2024-10-01T17:06:05.246Z (about 1 month ago)
- Language: Rust
- Size: 115 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# git-hooks-dispatch
Run hooks only in a directory where files are changed. Useful for monorepo.
![Crates.io](https://img.shields.io/crates/v/git-hooks-dispatch) ![test](https://github.com/akr4/git-hooks-dispatch/actions/workflows/test.yml/badge.svg)
## Install
Homebrew
```
brew tap akr4/tap
brew install git-hooks-dispatch
```Cargo
```
cargo install git-hooks-dispatch
```## Setting up
Set up hooks you want as the following:
Hook file (e.g. `.git/hooks/pre-commit`)
```
#!/bin/sh
git-hooks-dispatch $(basename $0) -- "$@"
```Make sure the file has permission to execute.
Then, in the child directories, you can set up hooks as they are in the project root directory.
For example:
`./sub-project1/git-hooks/pre-commit`
```
#!/bin/sh
npm run lint-staged
````./sub-project2/git-hooks/pre-commit`
```
#!/bin/sh
mvn antrun:run@ktlint-format
```## Hooks are executed recursively
In the below example, if `./foo/bar/B` is changed, `pre-commit` hooks are executed recursively in the following order:
1. `./foo/bar/git-hooks/pre-commit`
2. `./foo/git-hooks/pre-commit````
.
├── .git
│ └── hooks
│ └── pre-commit
└── foo
├── A
├── git-hooks
│ └── pre-commit
└── bar
├── B
└── git-hooks
└── pre-commit
```## Hooks dir name
`git-hooks-dispatch` searches a hook dir which name is `hooks-dir` or `.hooks-dir` by default. You can change it by `--hooks-dir` option.
### Manage hooks in your Git repository (recommended)
```
git config core.hooksPath git-hooks
```## Print logs
Setting `RUST_LOG` environment variable turns logging on.
```
RUST_LOG=debug git commit ...
```