diff options
Diffstat (limited to 'acid/acid-source')
-rwxr-xr-x | acid/acid-source | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/acid/acid-source b/acid/acid-source index 29b1516..351d3d0 100755 --- a/acid/acid-source +++ b/acid/acid-source @@ -12,8 +12,8 @@ # The caller should cache this hash value upon successful deployment. # # If a new version of the file tree is checked out, this file exits with code 1, -# otherwise a stale success exits with 0. On any error, no hash is printed, and -# we exit with 2. +# otherwise a stale success exits with 0. On any error, the null hash is +# printed, and we exit with 2. gethash() { git for-each-ref \ @@ -23,16 +23,21 @@ gethash() { "$1" # pattern } +fail() { + echo "$NULL_HASH" + exit 2 +} + cd "$CYCHE_SERVICE_DIR" # For <name>, limit to a-z, 0-9, -, _ if ! echo "$1" | grep -Eq '^[-_a-z0-9]*$'; then echo "Bad service name: $1" >&2 - exit 2 + fail fi if ! [ -d "$1" ]; then - git clone "$2" "$1" >&2 || exit 2 + git clone "$2" "$1" >&2 || fail touch "$1/.git/previous_hash" touch "$1/.git/previous_slug" fi @@ -40,14 +45,14 @@ fi cd "$1" git remote set-url origin "$2" >&2 # pick up url changes -git fetch --all --prune >&2 || exit 2 +git fetch --all --prune >&2 || fail prev=$(cat '.git/previous_hash') next=$(gethash "$3") if [ -z "$next" ]; then echo "No refs match $3" >&2 - exit 2 + fail fi echo "$next" |