Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository.

## Usage

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

```toml
[dev-dependencies]
Expand All @@ -27,7 +27,7 @@ Then run tests in your project directory.
$ cargo test
```

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

e.g.
Expand All @@ -47,7 +47,7 @@ cargo test
```

Note: cargo-husky does nothing on `cargo test` when
- hook script was already generated by the same version of cargo-husky
- a 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
Expand All @@ -73,7 +73,7 @@ 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:
All features are as follows:

| Feature | Description | Default |
|--------------------|---------------------------------------------------------------------|----------|
Expand All @@ -93,7 +93,7 @@ All features are follows:
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.
1. Create `.cargo-husky/hooks` directory at the same directory where the `.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`.
Expand All @@ -118,15 +118,15 @@ features = ["user-hooks"]
```

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

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`
When you don't want to install hooks for some reason, please set the `$CARGO_HUSKY_DONT_INSTALL_HOOKS`
environment variable.

```
Expand All @@ -137,14 +137,14 @@ 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].
Instead, cargo-husky sets Git hooks automatically on running tests by [cargo's build script feature][build scripts].

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.
If the `cargo-husky` crate is added to `dev-dependencies` section, it is compiled at running tests.
At the timing, [build script](./build.rs) is run and sets Git hook automatically.
The build script find the `.git` directory to put hooks based on `$OUT_DIR` environment variable
The build script finds 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,
Expand Down