1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p shfmt
3 # shellcheck shell=bash
5 # Copy me to .git/hooks/pre-commit
11 if [[ "$tmpdir" && -e "$tmpdir" ]];then
15 trap cleanup_tmpdir EXIT
17 # Check out the git index (what's about to be committed) in a temporary
18 # directory & run the supplied command there.
19 in_git_index_in_tmpdir() {
21 [[ "$tmpdir" && -d "$tmpdir" ]]
22 start_index=$(sha256sum "${GIT_INDEX_FILE:-.git/index}")
23 git checkout-index --prefix="$tmpdir/" -a
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!"
35 nix-shell --arg lint true --run './test.sh lint'
38 in_git_index_in_tmpdir verify