#!/bin/sh -e

. shell-quote

if [ x"$1" = x--help ]; then
    cat <<EOF
usage: gear-cronbuild <gear invocation arguments>

gear-cronbuild is a shell wrapper for the sequence
gear-cronbuild-apply-hooks && gear <gear invocation arguments> && gear-commit
EOF
    exit 0
fi

echo running gear-cronbuild-apply-hooks ...
gear-cronbuild-apply-hooks
echo running gear "$@" ...
gear "$@"

[ -n "\$(git status --porcelain -s -uno)" ] || {
echo unuse gear-commit
exit 0
}

commitmsg=
[ -x .gear/cronbuild-commitmsg ] && commitmsg=`.gear/cronbuild-commitmsg`
[ -n "$commitmsg" ] && commitmsg="\"$(quote_shell "$commitmsg")\""

echo running gear-commit ${commitmsg:+-m "$commitmsg"} ...
gear-commit ${commitmsg:+-m "$commitmsg"}
