Permalink
Browse files

pre-commit formatting

  • Loading branch information...
1 parent b9399f8 commit e68eed06e1551b13b414f924f4db6e1db0b3ecc8 @mrexodia mrexodia committed Aug 27, 2014
Showing with 36 additions and 0 deletions.
  1. BIN AStyle.dll
  2. BIN AStyleWhore.exe
  3. +33 −0 hooks/pre-commit
  4. +3 −0 install.bat
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Simple script to auto-format every source file before committing.
+#
+
+#check if the formatter is present
+if [ ! -f ./AStyleWhore.exe ]; then
+ echo "AStyleWhore not found!"
+ exit 0
+fi
+
+#format the code
+"./AStyleWhore.exe" Silent
+
+#exit when nothing needs to be done
+if [ $? == 0 ]; then
+ exit 0
+fi
+
+#stage the formatted files (when staged in this commit)
+gitFiles=$(git diff-index --name-only --cached HEAD)
+if [[ -n "${gitFiles}" ]]; then
+ for fname in $gitFiles; do
+ git add --all -- "${fname}"
+ done
+fi
+
+#cancel commit if the changes were undone by the formatting
+gitFiles=$(git diff-index --name-only --cached HEAD)
+if [ -z "$gitFiles" ]; then
+ "./AStyleWhore.exe" "After formatting, no files were staged..."
+ exit 1
+fi
View
@@ -0,0 +1,3 @@
+@echo off
+echo Run this to install the auto-format hook.
+copy hooks\pre-commit .git\hooks\pre-commit

0 comments on commit e68eed0

Please sign in to comment.