From e59029a94a289ad7a20235aa757d69c3dc2b0377 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 17 Jul 2021 08:14:08 -0700 Subject: [PATCH] git-hooks: add pre-commit hook for fmt and testing checks. --- git-hooks/README.md | 8 ++++++++ git-hooks/pre-commit | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 git-hooks/README.md create mode 100755 git-hooks/pre-commit diff --git a/git-hooks/README.md b/git-hooks/README.md new file mode 100644 index 0000000..ba36690 --- /dev/null +++ b/git-hooks/README.md @@ -0,0 +1,8 @@ +# Installing +Symlink the files in this directory into your `.git/hooks/` directory to +enable policies for this project. Example: + +```bash +$ cd .git/hooks +$ ln -s ../../git-hooks/pre-commit . +``` diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit new file mode 100755 index 0000000..fc61ab3 --- /dev/null +++ b/git-hooks/pre-commit @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -e -x +pushd () { + command pushd "$@" > /dev/null +} + +popd () { + command popd "$@" > /dev/null +} + +for workspace in rtchallenge rtiow; do + pushd ${workspace:?} + cargo fmt -- --check || (echo "To fix, run: cd ${workspace:?} && cargo fmt" && false) + popd +done + +RT=rtchallenge +AFFECTED="$(git diff-index --cached --name-only HEAD)" +#echo "AFFECTED $AFFECTED" +RT_AFFECTED=$(echo "${AFFECTED:?}" | grep ${RT:?} || true) +if [ ! -z "$RT_AFFECTED" ]; then + echo "Files for the rt challenge were touched, running tests" + cd ${RT:?} && cargo build --examples && cargo test +fi +# Uncomment to debug presubmit. +#exit 1