Commit e76e787c authored by Xueshan Feng's avatar Xueshan Feng
Browse files

fix(update): land branch refs on the remote head



VERSION=<branch> now resets the local branch to the freshly-fetched
origin tip with `checkout -B`, so it always lands on the remote head even
if the local branch had diverged (the old `merge --ff-only` aborted in
that case). ~/.otica is a shared sticky install that is never committed
to locally, so the reset is intended.

Changelog: fixed
Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent 47eb20c8
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
#!/bin/bash -eu
#
# Sync a local OTICA checkout to a ref. Clones if missing, then checks out
# <ref>: a branch is fast-forwarded; a tag or SHA is checked out detached. With
# no <ref> the newest v* release tag is used -- the checkout then stays on that
# ref until the next run (a sticky checkout, no per-build re-assertion).
# <ref>: a branch is reset to the remote head; a tag or SHA is checked out
# detached. With no <ref> the newest v* release tag is used -- the checkout then
# stays on that ref until the next run (a sticky checkout, no per-build
# re-assertion).
#
# Usage: otica-update.sh <repo> <dir> [<ref>]
#
@@ -36,10 +37,13 @@ if [ -z "${REF}" ]; then
    DEFAULTED=1
fi

# A branch can be fast-forwarded; a tag/SHA is a detached checkout.
# A branch -> land on the remote head; a tag/SHA is a detached checkout.
if git -C "${DIR}" show-ref -q --verify "refs/remotes/origin/${REF}"; then
    git -C "${DIR}" checkout -q "${REF}"
    git -C "${DIR}" merge -q --ff-only "origin/${REF}"
    # Pin the local branch to the freshly-fetched remote tip with -B so we
    # always end up on origin's head, even if the local branch had diverged
    # (a plain ff-only merge would abort here). ~/.otica is a shared, sticky
    # install that is never committed to locally, so resetting it is intended.
    git -C "${DIR}" checkout -q -B "${REF}" "origin/${REF}"
    echo "OTICA on branch ${REF} ($(git -C "${DIR}" rev-parse --short HEAD))"
elif [ "${DEFAULTED}" -eq 1 ]; then
    git -C "${DIR}" checkout -q "${REF}"