governance: collapse-archived.sh (fold 24 archived repos into perfops/archive/, sources left active)#28
Conversation
…nonical targets (subtree) + guarded delete
…ps/archive/<repo>/, leave sources active
There was a problem hiding this comment.
Code Review
This pull request introduces a bash script, collapse-archived.sh, to merge 24 archived repositories into their canonical targets using git subtree and optionally delete the source repositories. The review feedback focuses on critical safety improvements and error handling. Specifically, it suggests introducing a HAS_ERRORS flag to track failures across subshells, handling subshell failures gracefully during the subtree-merge and PR creation phases, and aborting the irreversible deletion phase if any errors occurred. Additionally, it recommends optimizing PR creation by resolving the default branch locally instead of making external GitHub API calls.
I am having trouble creating individual review comments. Click here to see my feedback.
governance/operations/collapse-archived.sh (133-135)
Add a critical safety check to abort the irreversible deletion of source repositories if any errors occurred during the subtree merge or PR creation phases. This prevents data loss for repositories that failed to merge successfully.
if $DO_DELETE; then
[ "${CONFIRM_DELETE:-no}" = "yes" ] || die "delete requested but CONFIRM_DELETE!=yes"
$APPLY || die "delete requested without --apply"
[ "$HAS_ERRORS" = "false" ] || die "Errors occurred during merge/PR phases. Aborting delete phase for safety."
governance/operations/collapse-archived.sh (23-24)
Initialize a safety flag HAS_ERRORS=false to track if any subtree merge or PR creation fails. This will allow us to prevent irreversible repository deletion in Phase 4 if any previous phase encountered errors.
WORKDIR="${WORKDIR:-$PWD/.collapse-archived}"
HAS_ERRORS=false
governance/operations/collapse-archived.sh (100-110)
Under set -euo pipefail, any failure inside the subshell (such as git fetch or git subtree add failing due to network issues or branch mismatch) will cause the entire script to exit immediately. Handling the subshell failure gracefully allows the script to continue processing other independent repositories, while setting HAS_ERRORS=true to prevent deletion of any source repositories later.
( cd "$WORKDIR/$trepo"
if git cat-file -e "HEAD:$tdir" 2>/dev/null; then
warn "$trepo:$tdir already exists — skipping $src (resolve manually)"
else
log "subtree $src ($db) -> $trepo/$tdir"
git remote add "s-$src" "$GH/$src.git" 2>/dev/null || true
git fetch -q "s-$src" "$db"
git subtree add --prefix="$tdir" "s-$src" "$db" \\
-m "absorb archived $src into $tdir (history-preserved)"
git remote remove "s-$src"
fi ) || { warn "Failed to subtree-merge $src into $trepo"; HAS_ERRORS=true; }
governance/operations/collapse-archived.sh (119-127)
Optimize PR creation by determining the default branch locally using git rev-parse instead of making a slow external GitHub API call (gh repo view) for every target repository. Additionally, handle subshell failures gracefully to prevent the script from crashing if a push or PR creation fails for one of the repositories.
( cd "$WORKDIR/$t"
br="$(git rev-parse --abbrev-ref HEAD)"
git push -q -u origin "$br"
base_branch="$(git rev-parse --abbrev-ref origin/HEAD 2>/dev/null | cut -d/ -f2-)"
base_branch="${base_branch:-main}"
gh pr create --repo "$OWNER/$t" \\
--base "$base_branch" \\
--head "$br" --draft \\
--title "absorb archived repos (history-preserved)" \\
--body "git-subtree merge of archived sources into this repo. History preserved. Review, then merge and run the delete phase." \\
|| warn "PR for $t skipped (may exist)" ) || { warn "Failed to push or create PR for $t"; HAS_ERRORS=true; }
…+ local base-branch resolve (review)
Adds
governance/operations/collapse-archived.sh— unarchives all 24 archived repos and folds each into theperfopsmonorepo underarchive/<repo>/viagit subtree(full history preserved). Per the chosen plan, sources are left active (unarchived) afterwards — no re-archive, no delete.Runs in your shell (the MCP integration cannot unarchive or subtree-merge). Dry-run by default;
--applyto execute. It clones the monorepo, subtree-merges each source intoarchive/<repo>/, pushes one branch and opens a draft PR onperfops.Review hardening applied: a failed source is isolated (skipped, others continue) instead of aborting the run; base branch resolved locally. The earlier review's delete-phase /
HAS_ERRORSnotes are obsolete — this version has no delete phase.Usage:
https://claude.ai/code/session_01XmPtu6BAhYCMX2SZXfbe76