]> git.scottworley.com Git - tablify/blob - git-pre-commit-hook
slice_concat_trait will never be stabilized. :(
[tablify] / git-pre-commit-hook
1 #!/usr/bin/env bash
2
3 # Copy me to .git/hooks/pre-commit
4
5 set -euo pipefail
6
7 if [[ "${GIT_REFLOG_ACTION:-}" == 'rebase (reword)' ]];then
8 exit 0
9 fi
10
11 tmpdir=
12 cleanup_tmpdir() {
13 if [[ "$tmpdir" && -e "$tmpdir" ]];then
14 rm -rf "$tmpdir"
15 fi
16 }
17 trap cleanup_tmpdir EXIT
18
19 # Check out the git index (what's about to be committed) in a temporary
20 # directory & run the supplied command there.
21 in_git_index_in_tmpdir() {
22 tmpdir=$(mktemp -d)
23 [[ "$tmpdir" && -d "$tmpdir" ]]
24 start_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
25 git checkout-index --prefix="$tmpdir/" -a
26 pushd "$tmpdir"
27 "$@"
28 popd
29 end_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
30 if [[ "$start_index" != "$end_index" ]];then
31 echo "Index changed while pre-commit tests were running. Aborting!"
32 exit 1
33 fi
34 }
35
36 verify() {
37 cargo test --frozen
38 cargo clippy --frozen -- -D warnings \
39 -W clippy::pedantic \
40 -W clippy::clone_on_ref_ptr \
41 -W clippy::if_then_some_else_none \
42 -W clippy::impl_trait_in_params \
43 -W clippy::pattern_type_mismatch \
44 -W clippy::shadow_reuse \
45 -W clippy::shadow_unrelated \
46 -W clippy::str_to_string \
47 -W clippy::try_err \
48 -A clippy::missing_errors_doc
49 find . -name target -prune -o -name '*.rs' -exec rustfmt --check -- {} +
50 }
51
52 in_git_index_in_tmpdir verify