[Libreoffice-commits] .: git-hooks/pre-commit

Jan Holesovsky kendy at kemper.freedesktop.org
Sun Oct 24 08:04:20 PDT 2010


 git-hooks/pre-commit |   19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

New commits:
commit b9960b48441a456e9ad935732361992496384886
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Sun Oct 24 17:00:45 2010 +0200

    Remove trailing whitespace and doubled empty lines during git commit.
    
    It is not necessary to bug the committer to do that - just remove the
    unnecessary whitespace automatically, and output a message that it has
    been done.

diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 2153c0b..0b53fbf 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -7,6 +7,8 @@
 #
 # To enable this hook, rename this file to "pre-commit".
 
+export LANG=POSIX
+
 if git rev-parse --verify HEAD >/dev/null 2>&1
 then
     against=HEAD
@@ -82,7 +84,22 @@ if test -n "$ERRORS" ; then
     exit 1
 fi
 
-# git way of checking whitespace
+# fix whitespace in code
+git diff-index --check --cached $against -- | \
+    grep ': trailing whitespace\.$' | \
+    sed 's/:[0-9]*: trailing whitespace.$//' | sort -u |
+    while read FILE ; do
+        if echo "$FILE" | grep -qs '\.\(c\|cpp\|cxx\|h\|hrc\|hxx\|idl\|java\)' ; then
+            # unfortunately, git stripspace works only as a filter :-(
+            TEMPFILE=`mktemp`
+            git stripspace < "$FILE" > "$TEMPFILE"
+            mv "$TEMPFILE" "$FILE"
+            git add "$FILE"
+            echo "Fixed whitespace in '$FILE'."
+        fi
+    done
+
+# check the rest of the files
 FILTER_PATCHES=`git diff-index --check --cached $against -- | sed '/\.\(diff\|patch\):/,/.*/d'`
 if [ -n "$FILTER_PATCHES" ] ; then
     echo "$FILTER_PATCHES"


More information about the Libreoffice-commits mailing list