summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2013-05-27 14:44:20 +0200
committerTor Andersson <tor.andersson@artifex.com>2013-05-27 14:50:57 +0200
commit01e8dbf74068362d769604df9e87d17c0c190f27 (patch)
tree02978e5270fe473cbfdd113a80ce343527682fd0
parent1e26928dd197a80572f4e298eceeec915677ba3d (diff)
downloadmupdf-01e8dbf74068362d769604df9e87d17c0c190f27.tar.xz
Add whitespace settings to .gitattributes and add commit hook script.
Run "bash scripts/gitsetup.sh" to set up the hooks after cloning.
-rw-r--r--.gitattributes14
-rwxr-xr-xscripts/githooks/pre-commit19
-rw-r--r--scripts/gitsetup.sh8
3 files changed, 40 insertions, 1 deletions
diff --git a/.gitattributes b/.gitattributes
index 3149f93d..10605e3d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,13 @@
-* text=auto
+# Macros:
+[attr]tabs whitespace=trailing-space,space-before-tab,indent-with-non-tab,tabwidth=4
+[attr]spaces whitespace=trailing-space,space-before-tab,tabs-in-indent
+
+# Files:
+* text=auto
+Make* tabs
+*.mk tabs
+*.[ch] tabs
+*.java tabs
+*.xml tabs
+memento.* spaces
+*.vcxproj* spaces
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
diff --git a/scripts/gitsetup.sh b/scripts/gitsetup.sh
new file mode 100644
index 00000000..10f2321e
--- /dev/null
+++ b/scripts/gitsetup.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Set up useful aliases:
+git config alias.wsfix "! git diff HEAD >P.diff && git apply -R P.diff && git apply --whitespace=fix P.diff && rm P.diff"
+git config alias.wsfixi "! git diff --cached >P.diff && git apply --cached -R P.diff && git apply --cached --whitespace=fix P.diff && rm P.diff"
+
+# Copy hooks:
+cp scripts/githooks/* .git/hooks/