From 70b4ca51dbd374f8c0105ecd647bf803a6155c4c Mon Sep 17 00:00:00 2001 From: Frank Bell Date: Wed, 14 Aug 2024 11:30:46 +0100 Subject: [PATCH] chore: add pre-push hook --- .githooks/README.md | 24 ++++++++++++++++++++++++ .githooks/pre-push | 14 ++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .githooks/README.md create mode 100755 .githooks/pre-push 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