diff --git a/README.md b/README.md index b6b5dbd..bae6f01 100644 --- a/README.md +++ b/README.md @@ -175,9 +175,23 @@ cd ~/.ai-workflows && git pull aiw-update ``` +If your upstream remote is not named `origin` (for example `redhat/main`), set +`AI_WORKFLOWS_REMOTE_REF` so `aiw-update` and the daily update check use the +same ref: + +```bash +export AI_WORKFLOWS_REMOTE_REF=redhat/main +aiw-update +``` + +For the systemd timer, add a drop-in under +`~/.config/systemd/user/ai-workflows-update-check.service.d/` with +`Environment=AI_WORKFLOWS_REMOTE_REF=redhat/main`, then +`systemctl --user daemon-reload`. + ### Optional: daily update notifier (Linux) -On Linux desktops with systemd user sessions and `notify-send`, `install.sh` can prompt to enable a daily check. If `~/.ai-workflows` is behind `origin/main`, you get a desktop notification suggesting `aiw-update`. +On Linux desktops with systemd user sessions and `notify-send`, `install.sh` can prompt to enable a daily check. If `~/.ai-workflows` is behind the configured upstream ref (default `origin/main`), you get a desktop notification suggesting `aiw-update`. ```bash ./install.sh cursor # prompts [y/N] when supported diff --git a/hack/aiw-update.sh b/hack/aiw-update.sh index b42dbb7..29b3b9c 100755 --- a/hack/aiw-update.sh +++ b/hack/aiw-update.sh @@ -2,7 +2,7 @@ # Pull latest ai-workflows and refresh installs if command wrappers changed. # # Usage: -# aiw-update # ff-only pull origin/main (must be on main) +# aiw-update # ff-only pull AI_WORKFLOWS_REMOTE_REF (default origin/main) # aiw-update --checkout-main # checkout main first, then pull # aiw-update --reinstall # always re-run install.sh for detected targets # aiw-update --project PATH # also reinstall Cursor skills for PATH (repeatable) @@ -12,6 +12,7 @@ set -euo pipefail INSTALL_DIR="${AI_WORKFLOWS_DIR:-${HOME}/.ai-workflows}" +REMOTE_REF="${AI_WORKFLOWS_REMOTE_REF:-origin/main}" REPO_DIR="$(readlink -f "$INSTALL_DIR")" CHECKOUT_MAIN=false FORCE_REINSTALL=false @@ -92,7 +93,7 @@ CURRENT_BRANCH="$(git branch --show-current 2>/dev/null || true)" if [[ "$CURRENT_BRANCH" != "main" ]] && ! $CHECKOUT_MAIN; then echo "ai-workflows: not on main (branch=${CURRENT_BRANCH:-detached})." >&2 echo " Use: aiw-update --checkout-main" >&2 - echo " Or rebase/merge origin/main into this branch, then retry." >&2 + echo " Or rebase/merge ${REMOTE_REF} into this branch, then retry." >&2 exit 1 fi @@ -102,10 +103,18 @@ if $CHECKOUT_MAIN; then git checkout main fi -git fetch origin main -if ! git pull --ff-only origin main; then - echo "ai-workflows: fast-forward pull from origin/main failed." >&2 - echo " Resolve local commits on main, or: git reset --hard origin/main (destructive)." >&2 +FETCH_REMOTE="${REMOTE_REF%%/*}" +FETCH_BRANCH="${REMOTE_REF#*/}" +if [[ "$FETCH_REMOTE" == "$REMOTE_REF" ]]; then + FETCH_REMOTE="origin" + FETCH_BRANCH="$REMOTE_REF" +fi +MERGE_REF="refs/remotes/${FETCH_REMOTE}/${FETCH_BRANCH}" + +git fetch "$FETCH_REMOTE" "$FETCH_BRANCH" +if ! git merge --ff-only "$MERGE_REF"; then + echo "ai-workflows: fast-forward pull from ${REMOTE_REF} failed." >&2 + echo " Resolve local commits on main, or: git reset --hard ${MERGE_REF} (destructive)." >&2 exit 1 fi diff --git a/hack/update-check.sh b/hack/update-check.sh index a69dd7d..091943c 100755 --- a/hack/update-check.sh +++ b/hack/update-check.sh @@ -40,6 +40,7 @@ if [[ "$FETCH_REMOTE" == "$REMOTE_REF" ]]; then FETCH_REMOTE="origin" FETCH_BRANCH="$REMOTE_REF" fi +MERGE_REF="refs/remotes/${FETCH_REMOTE}/${FETCH_BRANCH}" # Fetch quietly; network failures should not spam the user. if ! git fetch --quiet "$FETCH_REMOTE" "$FETCH_BRANCH" 2>/dev/null; then @@ -47,13 +48,13 @@ if ! git fetch --quiet "$FETCH_REMOTE" "$FETCH_BRANCH" 2>/dev/null; then exit 0 fi -if ! git rev-parse --verify "$REMOTE_REF" >/dev/null 2>&1; then - echo "ai-workflows: missing ref $REMOTE_REF" >&2 +if ! git rev-parse --verify "$MERGE_REF" >/dev/null 2>&1; then + echo "ai-workflows: missing ref $MERGE_REF" >&2 exit 0 fi -REMOTE_SHA="$(git rev-parse "$REMOTE_REF")" -BEHIND="$(git rev-list --count "HEAD..${REMOTE_REF}" 2>/dev/null || echo 0)" +REMOTE_SHA="$(git rev-parse "$MERGE_REF")" +BEHIND="$(git rev-list --count "HEAD..${MERGE_REF}" 2>/dev/null || echo 0)" BRANCH="$(git branch --show-current 2>/dev/null || echo detached)" UPDATE_CMD="aiw-update" if [[ "$BRANCH" != "main" ]]; then