]> git.scottworley.com Git - pluta-lesnura/blame_incremental - git-pre-commit-hook
Test with momentum_player
[pluta-lesnura] / git-pre-commit-hook
... / ...
CommitLineData
1#!/usr/bin/env bash
2
3# Copy me to .git/hooks/pre-commit
4
5set -euo pipefail
6
7tmpdir=
8cleanup_tmpdir() {
9 if [[ "$tmpdir" && -e "$tmpdir" ]];then
10 rm -rf "$tmpdir"
11 fi
12}
13trap cleanup_tmpdir EXIT
14
15# Check out the git index (what's about to be committed) in a temporary
16# directory & run the supplied command there.
17in_git_index_in_tmpdir() {
18 tmpdir=$(mktemp -d)
19 [[ "$tmpdir" && -d "$tmpdir" ]]
20 start_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
21 git checkout-index --prefix="$tmpdir/" -a
22 pushd "$tmpdir"
23 "$@"
24 popd
25 end_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
26 if [[ "$start_index" != "$end_index" ]];then
27 echo "Index changed while pre-commit tests were running. Aborting!"
28 exit 1
29 fi
30}
31
32verify() {
33 cargo test --offline
34 cargo clippy -- -D warnings -W clippy::pedantic
35 rustfmt --check src/*.rs
36}
37
38in_git_index_in_tmpdir verify