#!/usr/bin/env bash # Point git origin at Forgejo Submatter (local dev machine or CT 116 production host). # # Usage: # bash scripts/migrate-origin-to-forgejo.sh # FORGEJO_REPO_URL=https://forgejo.stillwell.cloud/rstillwell/Submatter.git bash scripts/migrate-origin-to-forgejo.sh # # On CT 116: # ssh root@192.168.68.116 'cd /opt/submatter && bash scripts/migrate-origin-to-forgejo.sh' set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$repo_root" forgejo_url="${FORGEJO_REPO_URL:-https://forgejo.stillwell.cloud/rstillwell/Submatter.git}" branch="${DEPLOY_BRANCH:-main}" if [[ ! -d .git ]]; then echo "[migrate-origin] ERROR: not a git repo: ${repo_root}" >&2 exit 1 fi old_url="$(git remote get-url origin 2>/dev/null || true)" if [[ -n "$old_url" && "$old_url" != "$forgejo_url" ]]; then echo "[migrate-origin] renaming old origin → github (was ${old_url})" git remote rename origin github 2>/dev/null || true if ! git remote get-url forgejo &>/dev/null; then git remote add forgejo "$old_url" fi fi if git remote get-url origin &>/dev/null; then git remote set-url origin "$forgejo_url" else git remote add origin "$forgejo_url" fi echo "[migrate-origin] origin → ${forgejo_url}" git remote -v echo "[migrate-origin] fetching ${branch}..." git fetch origin "$branch" || { echo "[migrate-origin] WARN: fetch failed — check Forgejo credentials (git config credential.helper)" >&2 exit 1 } current_branch="$(git branch --show-current 2>/dev/null || true)" if [[ "$current_branch" != "$branch" ]]; then git checkout "$branch" 2>/dev/null || git checkout -b "$branch" "origin/${branch}" fi echo "[migrate-origin] done. HEAD=$(git rev-parse --short HEAD)"