summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-08-08 22:06:21 -0400
committerMalfurious <m@lfurio.us>2023-08-08 22:06:21 -0400
commit2c3e2e404c87d01166471ec9f27912d654dec9bb (patch)
tree5b89256482654679727eafb35f665e1d517f0a3b
parent2a5c618158dc9a3c583e5ae054bb59b5870955af (diff)
downloadcychedelic-2c3e2e404c87d01166471ec9f27912d654dec9bb.tar.gz
cychedelic-2c3e2e404c87d01166471ec9f27912d654dec9bb.zip
acid: Update check_source
Script is renamed to 'cyche-source' and updated to account for a couple of potential edge-cases during a git update. Signed-off-by: Malfurious <m@lfurio.us>
-rwxr-xr-xacid/cyche-source (renamed from acid/check_source)29
1 files changed, 21 insertions, 8 deletions
diff --git a/acid/check_source b/acid/cyche-source
index b86e32d..dd290ac 100755
--- a/acid/check_source
+++ b/acid/cyche-source
@@ -1,23 +1,27 @@
#!/bin/bash
-# check_source <name> <url> <refspec>
+# cyche-source <name> <url> <ref-pattern>
#
# Check a git source for new updates. A local cache repository is cloned if
-# <name> doesn't exist. If updates are found, we attempt to checkout the
-# newest version according to <refspec> (see git-for-each-ref(1)).
+# <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) git commit hash is printed to stdout. If the file tree
-# is updated, this file exits non-zero.
+# 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.
+#
+# If the file tree is updated, this file exits non-zero.
gethash() {
git for-each-ref \
--count=1 \
--format='%(objectname)' \
--sort='-creatordate' \
- "$1" #ref
+ "$1" # pattern
}
-cd '/git'
+cd '/services'
if ! [ -d "$1" ]; then
git clone "$2" "$1" >&2
@@ -27,13 +31,22 @@ fi
cd "$1"
+git remote set-url origin "$2" >&2 # pick up url changes
git fetch --all --prune >&2
+
prev=$(cat '.git/previous_hash')
next=$(gethash "$3")
+
+if [ -z "$next" ]; then
+ # no matching refs
+ next="$prev"
+fi
+
echo "$next"
if [ "$prev" != "$next" ]; then
- git submodule deinit --all -f >/dev/null 2>&1
+ # update file tree
+ git submodule deinit --all --force >/dev/null 2>&1
git reset . >/dev/null 2>&1
git checkout . >/dev/null 2>&1
git clean -xffd >/dev/null 2>&1