{"id":13484831,"url":"https://github.com/rhysd/cargo-husky","last_synced_at":"2025-05-15T13:08:20.153Z","repository":{"id":50627988,"uuid":"151068206","full_name":"rhysd/cargo-husky","owner":"rhysd","description":"Setup Git hooks automatically for cargo projects with :dog:","archived":false,"fork":false,"pushed_at":"2024-07-23T08:04:32.000Z","size":53,"stargazers_count":340,"open_issues_count":27,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T22:35:04.665Z","etag":null,"topics":["cargo","development-tools","git","hook","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/cargo-husky","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-01T10:00:44.000Z","updated_at":"2025-04-09T06:51:51.000Z","dependencies_parsed_at":"2024-01-13T19:19:17.948Z","dependency_job_id":"711b0b64-df1a-4d62-8d78-281ef94c9d6e","html_url":"https://github.com/rhysd/cargo-husky","commit_stats":{"total_commits":88,"total_committers":6,"mean_commits":"14.666666666666666","dds":0.05681818181818177,"last_synced_commit":"45febeeefca4febf3dc867646a43bf1cb2eceb3a"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fcargo-husky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fcargo-husky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fcargo-husky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fcargo-husky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/cargo-husky/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","development-tools","git","hook","rust"],"created_at":"2024-07-31T17:01:35.456Z","updated_at":"2025-05-15T13:08:15.141Z","avatar_url":"https://github.com/rhysd.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"Husky for Cargo :dog:\n=====================\n[![Crates.io][crates-io badge]][cargo-husky]\n[![Build Status on Linux/macOS][travis-ci badge]][travis-ci]\n[![Build status on Windows][appveyor badge]][appveyor]\n\n[cargo-husky][] is a crate for Rust project managed by [cargo][]. In short, cargo-husky is a Rust\nversion of [husky][].\n\ncargo-husky is a development tool to set Git hooks automatically on `cargo test`. By hooking `pre-push`\nand running `cargo test` automatically, it prevents broken codes from being pushed to a remote\nrepository.\n\n\n## Usage\n\nPlease add `cargo-husky` crate to `[dev-dependencies]` section of your project's `Cargo.toml`.\n\n```toml\n[dev-dependencies]\ncargo-husky = \"1\"\n```\n\nThen run tests in your project directory.\n\n```\n$ cargo test\n```\n\nCheck Git hook was generated at `.git/hooks/pre-push`.\ncargo-husky generates a hook script which runs `cargo test` by default.\n\ne.g.\n\n```bash\n#!/bin/sh\n#\n# This hook was set by cargo-husky v1.0.0: https://github.com/rhysd/cargo-husky#readme\n# Generated by script /path/to/cargo-husky/build.rs\n# Output at /path/to/target/debug/build/cargo-husky-xxxxxx/out\n#\n\nset -e\n\necho '+cargo test'\ncargo test\n```\n\nNote: cargo-husky does nothing on `cargo test` when\n- hook script was already generated by the same version of cargo-husky\n- another hook script put by someone else is already there\n\nTo uninstall cargo-husky, please remove `cargo-husky` from your `[dev-dependencies]` and remove\nhook scripts from `.git/hooks`.\n\n[Japanese blogpost](https://rhysd.hatenablog.com/entry/2018/10/08/205041)\n\n\n## Customize behavior\n\nBehavior of cargo-husky can be customized by feature flags of `cargo-husky` package.\nYou can specify them in `[dev-dependencies.cargo-husky]` section of `Cargo.toml` instead of adding\n`cargo-husky` to `[dev-dependencies]` section.\n\ne.g.\n\n```toml\n[dev-dependencies.cargo-husky]\nversion = \"1\"\ndefault-features = false # Disable features which are enabled by default\nfeatures = [\"precommit-hook\", \"run-cargo-test\", \"run-cargo-clippy\"]\n```\n\nThis configuration generates `.git/hooks/pre-commit` script which runs `cargo test` and `cargo clippy`.\n\nAll features are follows:\n\n| Feature            | Description                                                         | Default  |\n|--------------------|---------------------------------------------------------------------|----------|\n| `run-for-all`      | Add `--all` option to command to run it for all crates in workspace | Enabled  |\n| `prepush-hook`     | Generate `pre-push` hook script                                     | Enabled  |\n| `precommit-hook`   | Generate `pre-commit` hook script                                   | Disabled |\n| `postmerge-hook`   | Generate `post-merge` hook script                                   | Disabled |\n| `run-cargo-test`   | Run `cargo test` in hook scripts                                    | Enabled  |\n| `run-cargo-check`  | Run `cargo check` in hook scripts                                   | Disabled |\n| `run-cargo-clippy` | Run `cargo clippy -- -D warnings` in hook scripts                   | Disabled |\n| `run-cargo-fmt`    | Run `cargo fmt -- --check` in hook scripts                          | Disabled |\n| `user-hooks`       | See below section                                                   | Disabled |\n\n\n## User Hooks\n\nIf generated hooks by `run-cargo-test` or `run-cargo-clippy` features are not sufficient for you,\nyou can create your own hook scripts and tell cargo-husky to put them into `.git/hooks` directory.\n\n1. Create `.cargo-husky/hooks` directory at the same directory where `.git` directory is put.\n2. Create hook files such as `pre-push`, `pre-commit`, ... as you like.\n3. Give an executable permission to the files (on \\*nix OS).\n4. Write `features = [\"user-hooks\"]` to `[dev-dependencies.cargo-husky]` section of your `Cargo.toml`.\n5. Check whether it works by removing an existing `target` directory and run `cargo test`.\n\ne.g.\n\n```\nyour-repository/\n├── .git\n└── .cargo-husky\n    └── hooks\n        ├── post-merge\n        └── pre-commit\n```\n\n```toml\n[dev-dependencies.cargo-husky]\nversion = \"1\"\ndefault-features = false\nfeatures = [\"user-hooks\"]\n```\n\ncargo-husky inserts an information header to copied hook files in `.git/hooks/` in order to detect\nself version update.\n\nNote that, when `user-hooks` feature is enabled, other all features are disabled. You need to prepare\nall hooks in `.cargo-husky/hooks` directory.\n\n\n## Ignore Installing Hooks\n\nWhen you don't want to install hooks for some reason, please set `$CARGO_HUSKY_DONT_INSTALL_HOOKS`\nenvironment variable.\n\n```\nCARGO_HUSKY_DONT_INSTALL_HOOKS=true cargo test\n```\n\n\n## How It Works\n\n[husky][] utilizes npm's hook scripts, but cargo does not provide such hooks.\nInstead, cargo-husky sets Git hook automatically on running tests by [cargo's build script feature][build scripts].\n\nBuild scripts are intended to be used for building third-party non-Rust code such as C libraries.\nThey are automatically run on compiling crates.\n\nIf `cargo-husky` crate is added to `dev-dependencies` section, it is compiled at running tests.\nAt the timing, [build script](./build.rs) is run and sets Git hook automatically.\nThe build script find the `.git` directory to put hooks based on `$OUT_DIR` environment variable\nwhich is automatically set by `cargo`.\n\ncargo-husky puts Git hook file only once for the same version. When it is updated to a new version,\nit overwrites the existing hook by detecting itself was updated.\n\ncargo-husky is developed on macOS and tested on Linux/macOS/Windows with 'stable' channel Rust toolchain.\n\n## License\n\n[MIT](./LICENSE.txt)\n\n[cargo-husky]: https://crates.io/crates/cargo-husky\n[cargo]: https://github.com/rust-lang/cargo\n[husky]: https://github.com/typicode/husky\n[build scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html\n[travis-ci badge]: https://travis-ci.org/rhysd/cargo-husky.svg?branch=master\n[travis-ci]: https://travis-ci.org/rhysd/cargo-husky\n[appveyor badge]: https://ci.appveyor.com/api/projects/status/whby8hq44tf9bob4/branch/master?svg=true\n[appveyor]: https://ci.appveyor.com/project/rhysd/cargo-husky/branch/master\n[crates-io badge]: https://img.shields.io/crates/v/cargo-husky.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fcargo-husky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Fcargo-husky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fcargo-husky/lists"}