diff --git a/.githooks/README.md b/.githooks/README.md new file mode 100644 index 000000000..278bdbc73 --- /dev/null +++ b/.githooks/README.md @@ -0,0 +1,24 @@ +# Git Hooks + +A pre-push hook which checks formatting of Rust files. Additional checks may be added in the future. + +# Prerequisites + +The following prerequisites are required: + +## Rust Nightly + +The nightly version of Rust provides additional formatting benefits over the stable version. + +```shell +rustup toolchain install nightly --profile minimal --component rustfmt +``` + +# Installation + +Use the following command in the root directory of the local repository to configure Git to use the hooks: + +```shell +git config core.hooksPath .githooks +``` + diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 000000000..babdb9945 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +# Check Rust formatting +if ! cargo +nightly fmt --all -- --check +then + echo "There are some code style issues." + # shellcheck disable=SC2006 + echo "Run 'cargo +nightly fmt --all' first." + exit 1 +fi + +exit 0 \ No newline at end of file