Submatter/scripts/migrate-origin-to-forgejo.sh
Randall Stillwell 9bde5960bf
Some checks failed
CI / Lint, type-check, test (push) Has been cancelled
Deploy homelab (CT 116) / Deploy to CT 116 (push) Has been cancelled
fix(deploy): collab URL, CT 116 prod compose, Forgejo migration
- Read NEXT_PUBLIC_COLLAB_SERVER_URL in yjs provider; bake NEXT_PUBLIC_* at Docker build
- Add prod compose, deploy scripts, CT 116 proxmox scaffolding
- Forgejo Actions CI/deploy; migrate-origin and post-migration scripts
2026-09-08 22:33:59 -05:00

52 lines
1.7 KiB
Bash
Executable file

#!/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)"