tools/scripts/git - Add recommended hooks
authorTim Otten <totten@civicrm.org>
Sun, 10 Mar 2013 11:10:55 +0000 (07:10 -0400)
committerTim Otten <totten@civicrm.org>
Sun, 10 Mar 2013 11:10:55 +0000 (07:10 -0400)
tools/scripts/git/commit-msg [new file with mode: 0755]
tools/scripts/git/post-checkout [new file with mode: 0755]
tools/scripts/git/post-merge [new file with mode: 0755]
tools/scripts/git/pre-commit [new file with mode: 0755]
tools/scripts/git/prepare-commit-msg [new file with mode: 0755]

diff --git a/tools/scripts/git/commit-msg b/tools/scripts/git/commit-msg
new file mode 100755 (executable)
index 0000000..0017268
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Note: This shell script should be designed and tested for cross-platform use
+
+# Reserved for future use
\ No newline at end of file
diff --git a/tools/scripts/git/post-checkout b/tools/scripts/git/post-checkout
new file mode 100755 (executable)
index 0000000..0017268
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Note: This shell script should be designed and tested for cross-platform use
+
+# Reserved for future use
\ No newline at end of file
diff --git a/tools/scripts/git/post-merge b/tools/scripts/git/post-merge
new file mode 100755 (executable)
index 0000000..0017268
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Note: This shell script should be designed and tested for cross-platform use
+
+# Reserved for future use
\ No newline at end of file
diff --git a/tools/scripts/git/pre-commit b/tools/scripts/git/pre-commit
new file mode 100755 (executable)
index 0000000..7dcbd6d
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# Note: This shell script should be designed and tested for cross-platform use
+
+# URL: https://github.com/totten/git-php-syntax-checker/
+# Author: Remigijus Jarmalavičius <remigijus@jarmalavicius.lt> 
+# Author: Vytautas Povilaitis <php-checker@vytux.lt>
+# License: GPLv3
+
+ROOT_DIR="$(pwd)/"
+LIST=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD)
+ERRORS_BUFFER=""
+for file in $LIST
+do
+    EXTENSION=$(echo "$file" | grep  -E ".php$|.module$|.inc$|.install$")
+    if [ "$EXTENSION" != "" ]; then
+        ERRORS=$(php -l $ROOT_DIR$file 2>&1 | grep "Parse error")
+        if [ "$ERRORS" != "" ]; then
+            if [ "$ERRORS_BUFFER" != "" ]; then
+                ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
+            else
+                ERRORS_BUFFER="$ERRORS"
+            fi
+            echo "Syntax errors found in file: $file "
+        fi
+    fi
+done
+if [ "$ERRORS_BUFFER" != "" ]; then
+    echo 
+    echo "These errors were found in try-to-commit files: "
+    echo -e $ERRORS_BUFFER
+    echo 
+    echo "Can't commit, fix errors first."
+    exit 1
+else
+    echo "Commited successfully."
+fi
diff --git a/tools/scripts/git/prepare-commit-msg b/tools/scripts/git/prepare-commit-msg
new file mode 100755 (executable)
index 0000000..0017268
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Note: This shell script should be designed and tested for cross-platform use
+
+# Reserved for future use
\ No newline at end of file