From a039aa4de5be7db9b59b8084b4a2a9876ec670b0 Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Tue, 5 Aug 2014 00:30:03 +0200 Subject: [PATCH] PROJECT: install script --- hooks/pre-commit | 33 +++++++++++++++++++++++++++++++++ install.bat | 3 +++ 2 files changed, 36 insertions(+) create mode 100644 hooks/pre-commit create mode 100644 install.bat diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100644 index 00000000..637f3ba4 --- /dev/null +++ b/hooks/pre-commit @@ -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 diff --git a/install.bat b/install.bat new file mode 100644 index 00000000..0ef42632 --- /dev/null +++ b/install.bat @@ -0,0 +1,3 @@ +@echo off +echo Run this to install the auto-format hook. +copy hooks\pre-commit .git\hooks\pre-commit \ No newline at end of file