]> git.scottworley.com Git - nix-pin-deps/commitdiff
git pre-commit hook
authorScott Worley <scottworley@scottworley.com>
Sat, 9 May 2026 08:04:19 +0000 (01:04 -0700)
committerScott Worley <scottworley@scottworley.com>
Sat, 9 May 2026 08:04:19 +0000 (01:04 -0700)
git-pre-commit-hook [new file with mode: 0755]
test.sh

diff --git a/git-pre-commit-hook b/git-pre-commit-hook
new file mode 100755 (executable)
index 0000000..85b4445
--- /dev/null
@@ -0,0 +1,22 @@
+#!/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"
+
+nix-shell --arg lint true --run './test.sh lint'
+
+popd
diff --git a/test.sh b/test.sh
index 146f90116465d62d5baf944cb731487a1ac1151f..c143632d4f8b55cd06cf16be9a35878c338f0130 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
 
 set -e
 
 
 set -e
 
@@ -8,7 +8,7 @@ find . -name build -prune -o -name dist -prune -o -name '*.py' -print0 |
 if [ "$1" = lint ];then
 
   pylint --reports=n --persistent=n --ignore-imports=y \
 if [ "$1" = lint ];then
 
   pylint --reports=n --persistent=n --ignore-imports=y \
-    -d fixme,invalid-name,missing-docstring,subprocess-run-check,too-few-public-methods *.py
+    -d fixme,invalid-name,missing-docstring,subprocess-run-check,too-few-public-methods -- *.py
 
   formatting_needs_fixing=$(
     find . -name '*.py' -print0 |
 
   formatting_needs_fixing=$(
     find . -name '*.py' -print0 |