raytracers/git-hooks/pre-commit

27 lines
638 B
Bash
Executable File

#!/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