#!/usr/bin/env bash # git-sync.sh - pull changes and run deploy.sh if updated set -euo pipefail REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${REPO_DIR}" git fetch --all --prune UPDATED=0 if git rev-parse --abbrev-ref --symbolic-full-name @{u} >/dev/null 2>&1; then LOCAL="$(git rev-parse @)" REMOTE="$(git rev-parse @{u})" if [ "${LOCAL}" != "${REMOTE}" ]; then UPDATED=1 fi else out="$(git pull --rebase 2>&1 || true)" if ! echo "${out}" | grep -q "Already up"; then UPDATED=1 fi fi if [ "${UPDATED}" -eq 1 ]; then echo "$(date -Iseconds) Repo updated -> running deploy.sh" "${REPO_DIR}/deploy.sh" else echo "$(date -Iseconds) Repo unchanged" fi