4 releases

0.1.2 Nov 21, 2024
0.1.1 Sep 30, 2024
0.1.0 Sep 30, 2024
0.0.1 Sep 28, 2024

#167 in Build Utils

Download history 506/week @ 2024-09-27 60/week @ 2024-10-04 37/week @ 2024-10-11 35/week @ 2024-10-18 20/week @ 2024-10-25 34/week @ 2024-11-01 9/week @ 2024-11-08 111/week @ 2024-11-15 77/week @ 2024-11-22 11/week @ 2024-11-29 50/week @ 2024-12-06

249 downloads per month
Used in intervalsets

MIT/Apache

21KB
215 lines

husky-rs

CI Crates.io Documentation License

husky-rs is a Git hooks management tool for Rust projects, inspired by Husky.

Features

  • Easy setup and configuration
  • Automatic installation of Git hooks
  • Support for all Git hooks
  • Cross-platform compatibility (Unix-like systems and Windows)

Quick Start

  1. Add to your Cargo.toml:

    [dev-dependencies]
    husky-rs = "0.1.2"
    
  2. Create hooks directory:

    mkdir -p .husky/hooks
    
  3. Add a hook (e.g., pre-commit):

    echo '#!/bin/sh\necho "Running pre-commit hook"' > .husky/hooks/pre-commit
    
  4. Install hooks:

    Note: Due to the execution mechanism of build.rs, running cargo clean is required when installing or updating hooks.

    cargo clean && cargo test
    

Tip: If you add this library to the [dependencies] section, both cargo build and cargo test will work. However, if it's added under [dev-dependencies], only cargo test will function as expected.

Usage

Supported Git Hooks

husky-rs aims to support a wide range of Git hooks, including:

  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • post-commit
  • pre-push

For a complete list of supported hooks, refer to the Git documentation.

If you encounter any unsupported hooks, please don't hesitate to open an issue.

Configuration

To skip hook installation:

NO_HUSKY_HOOKS=1 cargo build

Best Practices

  • Keep hooks lightweight to avoid slowing down Git operations
  • Use hooks for tasks like running tests, linting code, and validating commit messages
  • Non-zero exit status in a hook script will abort the Git operation

Development

For information on setting up the development environment, running tests, and contributing to the project, please refer to our Development Guide.

Troubleshooting

If you encounter any issues while using husky-rs, please check our Troubleshooting Guide for common problems and their solutions. If you can't find a solution to your problem, please open an issue on our GitHub repository.

Contributing

We welcome contributions! Please see our Contributing Guide for details on how to submit pull requests, report issues, or suggest improvements.

License

This project is licensed under either of:

at your option.

Changelog

For a detailed history of changes to this project, please refer to our CHANGELOG.md.

Acknowledgments

  • Inspired by cargo-husky
  • Thanks to the Rust community for their amazing tools and libraries

No runtime deps