All Projects → rhysd → Cargo Husky

rhysd / Cargo Husky

Licence: mit
Setup Git hooks automatically for cargo projects with 🐶

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Cargo Husky

Shadow Rs
A build-time information stored in your rust project.(binary,lib,cdylib,dylib)
Stars: ✭ 117 (-17.02%)
Mutual labels:  cargo
Misakahookfinder
御坂Hook提取工具—Galgame/文字游戏文本钩子提取
Stars: ✭ 125 (-11.35%)
Mutual labels:  hook
Webpack Internal Plugin Relation
🔎 a tiny tool to show the relation of webpack internal plugins & hooks
Stars: ✭ 135 (-4.26%)
Mutual labels:  hook
React Timer Hook
React timer hook
Stars: ✭ 118 (-16.31%)
Mutual labels:  hook
Kernel Roulette
A kernel module written in Rust
Stars: ✭ 124 (-12.06%)
Mutual labels:  cargo
Freereflection
A library that lets you use reflection without any restriction above Android P
Stars: ✭ 2,090 (+1382.27%)
Mutual labels:  hook
Fridaandroidtracer
A runnable jar that generate Javascript hook script to hook Android classes.
Stars: ✭ 114 (-19.15%)
Mutual labels:  hook
Elfhooker
兼容Android 32位和64位。基于EFL文件格式Hook的demo,hook了SurfaceFlinger进程的eglSwapBuffers函数,替换为new_eglSwapBuffers
Stars: ✭ 138 (-2.13%)
Mutual labels:  hook
Thermite
A Rake-based helper for building and distributing Rust-based Ruby extensions
Stars: ✭ 125 (-11.35%)
Mutual labels:  cargo
Cargo Flash
a cargo extension for programming microcontrollers
Stars: ✭ 134 (-4.96%)
Mutual labels:  cargo
Easyprotector
一行代码检测XP/调试/多开/模拟器/root
Stars: ✭ 1,732 (+1128.37%)
Mutual labels:  hook
Crate2nix
nix build file generator for rust crates
Stars: ✭ 123 (-12.77%)
Mutual labels:  cargo
Flutter hooks
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
Stars: ✭ 1,973 (+1299.29%)
Mutual labels:  hook
Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (-17.02%)
Mutual labels:  hook
Git Multimail
Send notification emails for pushes to a git repository (an improved version of post-receive-mail)
Stars: ✭ 135 (-4.26%)
Mutual labels:  hook
Next Sanity
Sanity.io toolkit for Next.js
Stars: ✭ 115 (-18.44%)
Mutual labels:  hook
Inquest
Inquest lets you add log statements to python without restarting your python instance. It helps you quickly uncover what is going wrong.
Stars: ✭ 130 (-7.8%)
Mutual labels:  development-tools
Cargo Edit
A utility for managing cargo dependencies from the command line.
Stars: ✭ 2,095 (+1385.82%)
Mutual labels:  cargo
Hookwormforandroid
一个基于Magisk&Riru的Module,可以助你用超低成本开发各种Hook插件,无须Xposed
Stars: ✭ 136 (-3.55%)
Mutual labels:  hook
Stegbrute
Fast Steganography bruteforce tool written in Rust useful for CTF's
Stars: ✭ 134 (-4.96%)
Mutual labels:  cargo

Husky for Cargo 🐶

Crates.io Build Status on Linux/macOS Build status on Windows

cargo-husky is a crate for Rust project managed by cargo. In short, cargo-husky is a Rust version of husky.

cargo-husky is a development tool to set Git hooks automatically on cargo test. By hooking pre-push and running cargo test automatically, it prevents broken codes from being pushed to a remote repository.

Usage

Please add cargo-husky crate to [dev-dependencies] section of your project's Cargo.toml.

[dev-dependencies]
cargo-husky = "1"

Then run tests in your project directory.

$ cargo test

Check Git hook was generated at .git/hooks/pre-push. cargo-husky generates a hook script which runs cargo test by default.

e.g.

#!/bin/sh
#
# This hook was set by cargo-husky v1.0.0: https://github.com/rhysd/cargo-husky#readme
# Generated by script /path/to/cargo-husky/build.rs
# Output at /path/to/target/debug/build/cargo-husky-xxxxxx/out
#

set -e

echo '+cargo test'
cargo test

Note: cargo-husky does nothing on cargo test when

  • hook script was already generated by the same version of cargo-husky
  • another hook script put by someone else is already there

To uninstall cargo-husky, please remove cargo-husky from your [dev-dependencies] and remove hook scripts from .git/hooks.

Japanese blogpost

Customize behavior

Behavior of cargo-husky can be customized by feature flags of cargo-husky package. You can specify them in [dev-dependencies.cargo-husky] section of Cargo.toml instead of adding cargo-husky to [dev-dependencies] section.

e.g.

[dev-dependencies.cargo-husky]
version = "1"
default-features = false # Disable features which are enabled by default
features = ["precommit-hook", "run-cargo-test", "run-cargo-clippy"]

This configuration generates .git/hooks/pre-commit script which runs cargo test and cargo clippy.

All features are follows:

Feature Description Default
run-for-all Add --all option to command to run it for all crates in workspace Enabled
prepush-hook Generate pre-push hook script Enabled
precommit-hook Generate pre-commit hook script Disabled
postmerge-hook Generate post-merge hook script Disabled
run-cargo-test Run cargo test in hook scripts Enabled
run-cargo-check Run cargo check in hook scripts Disabled
run-cargo-clippy Run cargo clippy -- -D warnings in hook scripts Disabled
run-cargo-fmt Run cargo fmt -- --check in hook scripts Disabled
user-hooks See below section Disabled

User Hooks

If generated hooks by run-cargo-test or run-cargo-clippy features are not sufficient for you, you can create your own hook scripts and tell cargo-husky to put them into .git/hooks directory.

  1. Create .cargo-husky/hooks directory at the same directory where .git directory is put.
  2. Create hook files such as pre-push, pre-commit, ... as you like.
  3. Give an executable permission to the files (on *nix OS).
  4. Write features = ["user-hooks"] to [dev-dependencies.cargo-husky] section of your Cargo.toml.
  5. Check whether it works by removing an existing target directory and run cargo test.

e.g.

your-repository/
├── .git
└── .cargo-husky
    └── hooks
        ├── post-merge
        └── pre-commit
[dev-dependencies.cargo-husky]
version = "1"
default-features = false
features = ["user-hooks"]

cargo-husky inserts an information header to copied hook files in .git/hooks/ in order to detect self version update.

Note that, when user-hooks feature is enabled, other all features are disabled. You need to prepare all hooks in .cargo-husky/hooks directory.

Ignore Installing Hooks

When you don't want to install hooks for some reason, please set $CARGO_HUSKY_DONT_INSTALL_HOOKS environment variable.

CARGO_HUSKY_DONT_INSTALL_HOOKS=true cargo test

How It Works

husky utilizes npm's hook scripts, but cargo does not provide such hooks. Instead, cargo-husky sets Git hook automatically on running tests by cargo's build script feature.

Build scripts are intended to be used for building third-party non-Rust code such as C libraries. They are automatically run on compiling crates.

If cargo-husky crate is added to dev-dependencies section, it is compiled at running tests. At the timing, build script is run and sets Git hook automatically. The build script find the .git directory to put hooks based on $OUT_DIR environment variable which is automatically set by cargo.

cargo-husky puts Git hook file only once for the same version. When it is updated to a new version, it overwrites the existing hook by detecting itself was updated.

cargo-husky is developed on macOS and tested on Linux/macOS/Windows with 'stable' channel Rust toolchain.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].