]> git.scottworley.com Git - rfc1751/blame - git-pre-commit-hook
Move word list to separate file
[rfc1751] / git-pre-commit-hook
CommitLineData
27ff981f
SW
1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p shfmt
3# shellcheck shell=bash
4
5# Copy me to .git/hooks/pre-commit
6
7set -euo pipefail
8
9tmpdir=
10cleanup_tmpdir() {
11 if [[ "$tmpdir" && -e "$tmpdir" ]];then
12 rm -rf "$tmpdir"
13 fi
14}
15trap cleanup_tmpdir EXIT
16
17# Check out the git index (what's about to be committed) in a temporary
18# directory & run the supplied command there.
19in_git_index_in_tmpdir() {
20 tmpdir=$(mktemp -d)
21 [[ "$tmpdir" && -d "$tmpdir" ]]
22 start_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
23 git checkout-index --prefix="$tmpdir/" -a
24 pushd "$tmpdir"
25 "$@"
26 popd
27 end_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
28 if [[ "$start_index" != "$end_index" ]];then
29 echo "Index changed while pre-commit tests were running. Aborting!"
30 exit 1
31 fi
32}
33
34verify() {
35 nix-shell --arg lint true --run './test.sh lint'
36}
37
38in_git_index_in_tmpdir verify