diff options
author | Przemyslaw Pawelczyk <przemoc@gmail.com> | 2015-02-14 15:34:13 +0100 |
---|---|---|
committer | Przemyslaw Pawelczyk <przemoc@gmail.com> | 2015-02-14 15:34:13 +0100 |
commit | 78d393659d1379825232cb605d9dfbd9d3c8624e (patch) | |
tree | 63ed0e443ebd0b6c3f2a6935dcd8965234ab20ad | |
parent | efce68713ffa1c2d3e8c22ca783a7e1010a3ddb3 (diff) |
Improve example hooks and remove bashisms in them.
-rw-r--r-- | examples/git-metapull | 49 | ||||
-rw-r--r-- | examples/pre-commit | 26 |
2 files changed, 39 insertions, 36 deletions
diff --git a/examples/git-metapull b/examples/git-metapull index 789149f..a7a3f7e 100644 --- a/examples/git-metapull +++ b/examples/git-metapull @@ -6,44 +6,41 @@ # and after getting confirmation, apply the changes. DO_MTIME=yes +MSFILE=".metadata" umask 0077 +[ "$DO_MTIME" = "yes" ] && MSFLAGS="-m" -if ! git-pull; then - echo "Failed to execute git-pull" >&2 - exit 1 -fi +exit_on_fail() { + "$@" + if [ $? -ne 0 ]; then + echo "Failed to execute: $@" >&2 + exit 1 + fi +} + +exit_on_fail \ + git-pull -if [ ! -e ".metadata" ]; then - echo ".metadata missing" >&2 - exit 1 +if [ ! -e "$MSFILE" ]; then + echo "\"$MSFILE\" missing" >&2 + exit 1 fi echo "Going to apply the following metadata changes" >&2 -if [ "$DO_MTIME" = "yes" ]; then - metastore -c -m >&2 -else - metastore -c >&2 -fi -echo -n "Ok to apply? (y/n): " >&2 -read -n1 REPLY +metastore -c $MSFLAGS -f "$MSFILE" >&2 + +printf "%s" "Ok to apply? (y/n): " >&2 +read REPLY echo "" if [ "$REPLY" != "y" ]; then - echo "Aborted" >&2 - exit 1 -fi - -if [ "$DO_MTIME" = "yes" ]; then - flags="-a -m" -else - flags="-a" + echo "Aborted" >&2 + exit 1 fi -if ! metastore $flags; then - echo "Failed to execute metastore $flags" >&2 - exit 1 -fi +exit_on_fail \ + metastore -a $MSFLAGS -f "$MSFILE" exit 0 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 |