diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/git-metapull | 51 | ||||
-rw-r--r-- | examples/post-checkout | 24 | ||||
-rw-r--r-- | examples/pre-commit | 28 |
3 files changed, 65 insertions, 38 deletions
diff --git a/examples/git-metapull b/examples/git-metapull index 789149f..8842b11 100644 --- a/examples/git-metapull +++ b/examples/git-metapull @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # This script can be used instead of git-pull when updating a remote # repo to make sure the metadata matches what is stored in the repo. @@ -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/post-checkout b/examples/post-checkout new file mode 100644 index 0000000..bd4de15 --- /dev/null +++ b/examples/post-checkout @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to set metadata information using +# metastore after each checkout. + +MSFILE=".metadata" + +exit_on_fail() { + "$@" + if [ $? -ne 0 ]; then + echo "Failed to execute: $@" >&2 + exit 1 + fi +} + +if [ ! -e "$MSFILE" ]; then + echo "\"$MSFILE\" missing" >&2 + exit 1 +fi + +exit_on_fail \ + metastore -a -m -e -E -q -f "$MSFILE" + +exit 0 diff --git a/examples/pre-commit b/examples/pre-commit index 1b5d5c6..b91635d 100644 --- a/examples/pre-commit +++ b/examples/pre-commit @@ -1,21 +1,27 @@ -#!/bin/bash +#!/bin/sh # # 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 |