summaryrefslogtreecommitdiffstats
path: root/acid/cyche-source
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-08-18 13:00:31 -0400
committerMalfurious <m@lfurio.us>2023-08-18 13:45:53 -0400
commit4d72b3f149a2bb80b5d371e661eb80324e2442bc (patch)
tree06db695d8282439625a30120ccf1bb6252c5d488 /acid/cyche-source
parentd5c380f477f2913effd632cf58aff287062bf593 (diff)
downloadcychedelic-4d72b3f149a2bb80b5d371e661eb80324e2442bc.tar.gz
cychedelic-4d72b3f149a2bb80b5d371e661eb80324e2442bc.zip
acid: Improve git error handling
Exit early from the cyche-source script on key git errors, where previously we would mindlessly continue on to execute a bunch of broken commands. Errors at this stage should be caught to prevent an attempt to build and deploy the code (even --force 'd builds). Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'acid/cyche-source')
-rwxr-xr-xacid/cyche-source20
1 files changed, 11 insertions, 9 deletions
diff --git a/acid/cyche-source b/acid/cyche-source
index dd290ac..e53ef6f 100755
--- a/acid/cyche-source
+++ b/acid/cyche-source
@@ -6,12 +6,14 @@
# <name> doesn't exist. If updates are found, we attempt to checkout the newest
# version according to <ref-pattern> (see <pattern> from git-for-each-ref(1)).
#
-# The new (or current, if no update occurred) object hash is printed to stdout.
-# This may be a commit hash. However, if <ref-pattern> matches an annotated tag,
-# then the hash names the tag object. The caller should cache this hash value
-# upon successful deployment.
+# On a successful run, the new object hash is printed to stdout (or the previous
+# hash, if no update occurred). This may be a commit hash. However, if
+# <ref-pattern> matches an annotated tag, then the hash refers to the tag object.
+# The caller should cache this hash value upon successful deployment.
#
-# If the file tree is updated, this file exits non-zero.
+# 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.
gethash() {
git for-each-ref \
@@ -24,7 +26,7 @@ gethash() {
cd '/services'
if ! [ -d "$1" ]; then
- git clone "$2" "$1" >&2
+ git clone "$2" "$1" >&2 || exit 2
touch "$1/.git/previous_hash"
touch "$1/.git/previous_slug"
fi
@@ -32,14 +34,14 @@ fi
cd "$1"
git remote set-url origin "$2" >&2 # pick up url changes
-git fetch --all --prune >&2
+git fetch --all --prune >&2 || exit 2
prev=$(cat '.git/previous_hash')
next=$(gethash "$3")
if [ -z "$next" ]; then
- # no matching refs
- next="$prev"
+ echo "No refs match $3" >&2
+ exit 2
fi
echo "$next"