summaryrefslogtreecommitdiff
path: root/scripts/githooks
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/githooks')
-rwxr-xr-xscripts/githooks/pre-commit19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/githooks/pre-commit b/scripts/githooks/pre-commit
new file mode 100755
index 00000000..fec7128f
--- /dev/null
+++ b/scripts/githooks/pre-commit
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# pre-commit hook to fix whitespace errors
+#
+# Uses the core.whitespace or .gitattributes whitespace=... settings.
+#
+# see also: "man git-config" under core.whitespace
+# see also: "man gitattributes"
+#
+
+PATCH=P.diff
+
+if ! git diff --cached --check --quiet
+then
+ git diff --cached > $PATCH
+ git apply --cached --whitespace=fix -R $PATCH
+ git apply --cached --whitespace=fix $PATCH
+ rm $PATCH
+fi