]> git.scottworley.com Git - nix-env-apps/blobdiff - git-pre-commit-hook
mypy, pylint, autopep8, & pre-commit hook to run them
[nix-env-apps] / git-pre-commit-hook
diff --git a/git-pre-commit-hook b/git-pre-commit-hook
new file mode 100755 (executable)
index 0000000..ce47614
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+# Copy me to .git/hooks/pre-commit
+
+set -e
+
+cleanup() {
+  if [[ "$D" && -e "$D" ]];then
+    rm -rf "$D"
+  fi
+}
+trap cleanup EXIT
+
+D=$(mktemp -d)
+[[ "$D" && -d "$D" ]]
+
+git checkout-index --prefix="$D/" -a
+pushd "$D"
+
+# So we don't confuse the inner git invocations inside the tests with
+# the outer git invocation that's trying to commit a change.
+unset GIT_AUTHOR_DATE
+unset GIT_AUTHOR_EMAIL
+unset GIT_AUTHOR_NAME
+unset GIT_CONFIG_PARAMETERS
+unset GIT_EXEC_PATH
+unset GIT_INDEX_FILE
+unset GIT_PREFIX
+
+nix-shell --arg lint true --run './test.sh lint'
+
+popd