134 lines
4.4 KiB
Bash
Executable File
134 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# =============================================================================
|
|
# phase10_post_check.sh — Verify local repo remote cutover to Gitea
|
|
# Checks for each discovered local repo:
|
|
# 1. origin points to Gitea org/repo
|
|
# 2. github points to GitHub owner/repo
|
|
# 3. every local branch tracks origin/<branch>
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "${SCRIPT_DIR}/lib/common.sh"
|
|
source "${SCRIPT_DIR}/lib/phase10_common.sh"
|
|
|
|
load_env
|
|
require_vars GITEA_ORG_NAME GITEA_DOMAIN GITHUB_USERNAME
|
|
|
|
phase_header 10 "Local Repo Remote Cutover — Post-Check"
|
|
|
|
LOCAL_REPO_ROOT="${PHASE10_LOCAL_ROOT:-/Users/s/development}"
|
|
EXPECTED_REPO_COUNT="${PHASE10_EXPECTED_REPO_COUNT:-3}"
|
|
INCLUDE_PATHS=()
|
|
|
|
if [[ -n "${PHASE10_INCLUDE_PATHS:-}" ]]; then
|
|
# Space-delimited list of extra repo roots to include in phase10 discovery.
|
|
read -r -a INCLUDE_PATHS <<< "${PHASE10_INCLUDE_PATHS}"
|
|
fi
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--local-root=*) LOCAL_REPO_ROOT="${arg#*=}" ;;
|
|
--expected-count=*) EXPECTED_REPO_COUNT="${arg#*=}" ;;
|
|
--include-path=*) INCLUDE_PATHS+=("${arg#*=}") ;;
|
|
--help|-h)
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [options]
|
|
|
|
Options:
|
|
--local-root=PATH Root folder containing local repos (default: /Users/s/development)
|
|
--expected-count=N Require exactly N discovered repos (default: 3, 0 disables)
|
|
--include-path=PATH Explicit repo root to include (repeatable)
|
|
--help Show this help
|
|
EOF
|
|
exit 0
|
|
;;
|
|
*)
|
|
log_error "Unknown argument: $arg"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if ! [[ "$EXPECTED_REPO_COUNT" =~ ^[0-9]+$ ]]; then
|
|
log_error "--expected-count must be a non-negative integer"
|
|
exit 1
|
|
fi
|
|
|
|
if ! phase10_discover_local_repos "$LOCAL_REPO_ROOT" "$GITHUB_USERNAME" "$SCRIPT_DIR" 0; then
|
|
exit 1
|
|
fi
|
|
|
|
for include_path in "${INCLUDE_PATHS[@]}"; do
|
|
[[ -z "$include_path" ]] && continue
|
|
if ! phase10_include_repo_path "$include_path" "$GITHUB_USERNAME"; then
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
phase10_sort_repo_arrays
|
|
|
|
if ! phase10_enforce_expected_count "$EXPECTED_REPO_COUNT" "$LOCAL_REPO_ROOT"; then
|
|
exit 1
|
|
fi
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
for i in "${!PHASE10_REPO_NAMES[@]}"; do
|
|
repo_name="${PHASE10_REPO_NAMES[$i]}"
|
|
repo_path="${PHASE10_REPO_PATHS[$i]}"
|
|
github_url="${PHASE10_GITHUB_URLS[$i]}"
|
|
gitea_url="$(phase10_canonical_gitea_url "$GITEA_DOMAIN" "$GITEA_ORG_NAME" "$repo_name")"
|
|
|
|
log_info "--- Checking repo: ${repo_name} (${repo_path}) ---"
|
|
|
|
origin_url="$(git -C "$repo_path" remote get-url origin 2>/dev/null || true)"
|
|
if [[ -n "$origin_url" ]] && phase10_url_is_gitea_repo "$origin_url" "$GITEA_DOMAIN" "$GITEA_ORG_NAME" "$repo_name"; then
|
|
log_success "origin points to Gitea (${gitea_url})"
|
|
PASS=$((PASS + 1))
|
|
else
|
|
log_error "FAIL: origin does not point to ${gitea_url} (found: ${origin_url:-<missing>})"
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
|
|
github_remote_url="$(git -C "$repo_path" remote get-url github 2>/dev/null || true)"
|
|
if [[ -n "$github_remote_url" ]] && phase10_url_is_github_repo "$github_remote_url" "$GITHUB_USERNAME" "$repo_name"; then
|
|
log_success "github points to GitHub (${github_url})"
|
|
PASS=$((PASS + 1))
|
|
else
|
|
log_error "FAIL: github does not point to ${github_url} (found: ${github_remote_url:-<missing>})"
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
|
|
branch_count=0
|
|
while IFS= read -r branch; do
|
|
[[ -z "$branch" ]] && continue
|
|
branch_count=$((branch_count + 1))
|
|
upstream_remote=$(git -C "$repo_path" for-each-ref --format='%(upstream:remotename)' "refs/heads/${branch}")
|
|
upstream_short=$(git -C "$repo_path" for-each-ref --format='%(upstream:short)' "refs/heads/${branch}")
|
|
if [[ "$upstream_remote" == "origin" ]] && [[ "$upstream_short" == "origin/${branch}" ]]; then
|
|
log_success "branch ${branch} tracks origin/${branch}"
|
|
PASS=$((PASS + 1))
|
|
else
|
|
log_error "FAIL: branch ${branch} tracks ${upstream_short:-<none>} (expected origin/${branch})"
|
|
FAIL=$((FAIL + 1))
|
|
fi
|
|
done < <(git -C "$repo_path" for-each-ref --format='%(refname:short)' refs/heads)
|
|
|
|
if [[ "$branch_count" -eq 0 ]]; then
|
|
log_warn "No local branches found in ${repo_name}"
|
|
fi
|
|
done
|
|
|
|
printf '\n'
|
|
log_info "Results: ${PASS} passed, ${FAIL} failed"
|
|
|
|
if [[ "$FAIL" -gt 0 ]]; then
|
|
log_error "Phase 10 post-check FAILED"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "Phase 10 post-check PASSED — local repos track Gitea origin"
|