From 78d393659d1379825232cb605d9dfbd9d3c8624e Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Sat, 14 Feb 2015 15:34:13 +0100 Subject: Improve example hooks and remove bashisms in them. --- examples/pre-commit | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'examples/pre-commit') diff --git a/examples/pre-commit b/examples/pre-commit index 1b5d5c6..5bed048 100644 --- a/examples/pre-commit +++ b/examples/pre-commit @@ -3,19 +3,25 @@ # An example hook script to store metadata information using # metastore on each commit. -if ! metastore -s; then - echo "Failed to execute metastore -s" >&2 - exit 1 -fi +MSFILE=".metadata" -if [ ! -e ".metadata" ]; then - echo ".metadata missing" >&2 - exit 1 -fi +exit_on_fail() { + "$@" + if [ $? -ne 0 ]; then + echo "Failed to execute: $@" >&2 + exit 1 + fi +} + +exit_on_fail \ + metastore -s -f "$MSFILE" -if ! git-add .metadata; then - echo "Failed to execute git-add .metadata" >&2 +if [ ! -e "$MSFILE" ]; then + echo "\"$MSFILE\" missing" >&2 exit 1 fi +exit_on_fail \ + git-add "$MSFILE" + exit 0 -- cgit v1.2.1