#!/usr/bin/env bash # sync_repos.sh — mirror branches + tags between the two Gitea instances that # host the Timesheet repo, in BOTH directions. # # dadeschools : gitea.dadeschools.net / Contractor/Timesheet (HTTPS — SSH:2222 is flaky) # prgs : gitea-ssh.prgs.cc:2222 / Scaled-Tech-Consulting/Timesheet (SSH — HTTPS host 404s) # # Safety model: # * ADDITIVE by default. A branch on only one side is pushed to the other. # * A shared branch where one side is strictly ahead is fast-forwarded. # * A shared branch that has DIVERGED is skipped with a loud warning # (never auto-overwritten). Resolve those by hand. # * Dry-run by default; pass --apply to actually push. --force lets the # fast-forward pushes use --force (still skips diverged branches). # # Auth is automatic via the macOS keychain (`git credential fill`), same as the # other Gitea-Tools scripts. Run it from inside any clone of the repo, or set # REPO=/path/to/clone. # # Usage: # ./sync_repos.sh # dry run — show what WOULD sync # ./sync_repos.sh --apply # perform the sync # ./sync_repos.sh --apply --force set -euo pipefail # --- config ------------------------------------------------------------------ DADE_URL="https://gitea.dadeschools.net/Contractor/Timesheet.git" PRGS_URL="ssh://git@gitea-ssh.prgs.cc:2222/Scaled-Tech-Consulting/Timesheet.git" REPO="${REPO:-$(pwd)}" APPLY=0 FORCE=0 for arg in "$@"; do case "$arg" in --apply) APPLY=1 ;; --force) FORCE=1 ;; -h|--help) sed -n '2,30p' "$0"; exit 0 ;; *) echo "Unknown flag: $arg" >&2; exit 2 ;; esac done cd "$REPO" git rev-parse --git-dir >/dev/null 2>&1 || { echo "Not a git repo: $REPO" >&2; exit 1; } note() { printf '%s\n' "$*"; } action() { if [ "$APPLY" -eq 1 ]; then printf ' ✓ %s\n' "$*"; else printf ' [dry] %s\n' "$*"; fi; } # --- fetch both sides into private namespaces -------------------------------- note "==> Fetching both remotes..." git fetch --prune "$DADE_URL" '+refs/heads/*:refs/sync/dade/*' 'refs/tags/*:refs/tags/*' >/dev/null 2>&1 \ || { echo "ERROR: cannot fetch dadeschools (check VPN/keychain)" >&2; exit 1; } git fetch --prune "$PRGS_URL" '+refs/heads/*:refs/sync/prgs/*' >/dev/null 2>&1 \ || { echo "ERROR: cannot fetch prgs (check SSH access)" >&2; exit 1; } # --- reconcile branches ------------------------------------------------------ # push