From 3d72f7a0de4f733d91754374ea8a0047baa6ce21 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 30 Jan 2016 22:58:57 +0100 Subject: [PATCH] Pre commit hook Testing php code linting --- .gitignore | 1 + pre_commit.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 .gitignore create mode 100644 pre_commit.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..530234e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/ diff --git a/pre_commit.sh b/pre_commit.sh new file mode 100644 index 0000000..b984d52 --- /dev/null +++ b/pre_commit.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +git diff --cached --name-only | while read FILE; do +if [[ "$FILE" =~ ^.+(php)$ ]]; then + if [[ -f ${FILE} ]]; then + php -l "$FILE" 1> /dev/null + if [ $? -ne 0 ]; then + echo -e "\e[1;31m\tAborting commit due to files with syntax errors.\e[0m" >&2 + exit 1 + fi + fi +fi +done || exit $?