diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2020-06-17 20:10:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-17 20:10:47 -0400 |
| commit | 4c765547fb6ff0697d11d0162c0bd3d7f5655ce5 (patch) | |
| tree | ce6638a29c178650c18037df4214809d13b13702 | |
| parent | ff759a078975de54ffee4383912834393bd9a0a3 (diff) | |
| parent | 0b669acac07a2b325316a46cca01a5cb85eede3b (diff) | |
Merge pull request #6 from ojacobson/travis-githooks
Provide a git hook to automate tests.
| -rwxr-xr-x | .git-hooks/pre-commit | 8 | ||||
| -rwxr-xr-x | .git-hooks/pre-merge-commit | 7 | ||||
| -rw-r--r-- | .travis.yml | 3 | ||||
| -rw-r--r-- | README.md | 41 |
4 files changed, 58 insertions, 1 deletions
diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit new file mode 100755 index 0000000..7fd95fb --- /dev/null +++ b/.git-hooks/pre-commit @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# dup of the list in .travis.yml +cargo build --locked +cargo test +cargo fmt -- --check +cargo clippy -- --deny warnings +cargo udeps --locked --all-targets diff --git a/.git-hooks/pre-merge-commit b/.git-hooks/pre-merge-commit new file mode 100755 index 0000000..efdecc9 --- /dev/null +++ b/.git-hooks/pre-merge-commit @@ -0,0 +1,7 @@ +#!/bin/bash -e + +# Run the pre-commit hook on merges, too. + +if [ -x .git-hooks/pre-commit ]; then + exec .git-hooks/pre-commit +fi diff --git a/.travis.yml b/.travis.yml index 40cd744..3980786 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,9 @@ install: - cargo install cargo-udeps - cargo build +# dup of the list in .git-hooks/pre-commit script: - - cargo build + - cargo build --locked - cargo test - cargo fmt -- --check - cargo clippy -- --deny warnings @@ -38,3 +38,44 @@ the page as a suggestion. Stable links provide the user with an index into this list. When you insert new items, insert them at the end. + +## Git hooks + +This project includes a pre-commit and a pre-merge-commit hook to run tests. +Using this hook is optional, but it'll catch a lot of minor breakage before +Travis does. + +**Security note**: Enabling in-repository hooks means that anyone who can commit +code to this repository can run that code on your computer. Only do this if +you're willing to take that chance. + +To set this up: + +* Install additional Rust components: + + ```bash + rustup component add clippy rustfmt + ``` + +* Install `cargo-udeps`: + + ```bash + cargo install cargo-udeps + ``` + +* Configure Git to use these hooks: + + ```bash + git config core.hooksPath .git-hooks + ``` + +This only needs to be done once, and applies only to this project. To undo this, +unset `core.hooksPath`: + +```bash +git config --unset core.hooksPath +``` + +You can also temporarily suppress the hook with `git commit --no-verify`, if you +have broken code you want to check in, or if the internet is unavailable for +Cargo to download dependencies. |
