https://github.com/daynin/monk
Monk is a simple Git hooks manager
https://github.com/daynin/monk
git git-hooks rust
Last synced: 8 months ago
JSON representation
Monk is a simple Git hooks manager
- Host: GitHub
- URL: https://github.com/daynin/monk
- Owner: daynin
- License: mit
- Created: 2024-09-19T17:47:32.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-20T17:57:18.000Z (over 1 year ago)
- Last Synced: 2025-02-15T05:02:59.924Z (over 1 year ago)
- Topics: git, git-hooks, rust
- Language: Rust
- Homepage: https://crates.io/crates/monk
- Size: 153 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Monk is a simple Git hooks manager
### Monk's features:
- 🦀 **Easily set up in your Rust project.** No need to install additional package managers.
- ⚙️ **Works with custom `build.rs` files.** Automate the hooks installation process.
- 💻 **Run your hooks via CLI.** Test your hooks without triggering them via Git.
> Keep calm, monk will protect your repo!
### Installation
You can install it using `cargo`:
```sh
cargo install monk
```
#### Or
You can add it as a build dependency:
```sh
cargo add --build monk
```
Then create a `build.rs` file:
```rust
pub fn main() {
monk::init();
}
```
In this case, `monk` will be installed automatically and will initialize all hooks from `monk.yaml`
.
This is the most convenient option for Rust projects, as it doesn't require contributors to install `monk` manually.
#### Installing monk with Nix
You can also install `monk` using Nix:
```sh
nix profile install github:daynin/monk
```
#### Installing monk with Guix
You can install `monk` using GNU Guix directly from GitHub:
```sh
# Install latest version from main branch
guix package -f <(curl -s https://raw.githubusercontent.com/daynin/monk/main/monk.scm)
```
Note: This will automatically fetch and build the latest version from the main branch.
### Usage
Create a configuration file named `monk.yaml` in your project root:
#### Simple Configuration
```yaml
pre-commit:
commands:
- cargo fmt -- --check
- cargo clippy -- -D warnings
pre-push:
commands:
- cargo test
```
#### Path-Based Configuration
For projects with multiple modules or mixed technologies, you can configure different hooks for different paths:
```yaml
pre-commit:
paths:
"api/":
commands:
- cargo fmt -- --check
- cargo clippy -- -D warnings
working_directory: "api"
"frontend/":
commands:
- npm run lint
- npm test
working_directory: "frontend"
"shared/":
commands:
- cargo fmt -- --check
- cargo clippy -- -D warnings
- cargo test
working_directory: "shared"
pre-push:
paths:
"api/":
commands:
- cargo test
- cargo build --release
working_directory: "api"
"frontend/":
commands:
- npm run build
working_directory: "frontend"
# Global hooks (run for any changes)
commit-msg:
commands:
- echo "Validating commit message..."
```
**Path-based features:**
- 🎯 **Selective execution**: Only runs hooks for paths with changed files
- 📁 **Working directory**: Each hook can specify its working directory
- 🔄 **Multi-module support**: Perfect for monorepos with multiple Rust crates
- 🌐 **Mixed technology**: Supports different tech stacks in the same repo
If you installed `monk` manually, run:
```sh
monk install
```
If you added it as a build dependency and set up `build.rs` as shown above, the hooks will be installed automatically when you build your project.
#### Running hooks manually
To run specific hooks manually, use the `run` command
```sh
monk run pre-commit
```
#### Removing Hooks
`monk` automatically creates backup files for existing hooks and restores them when you remove monk's hooks.
To remove the hooks, run:
```sh
monk uninstall
```