Skip to content

feat(gh): use detached review worktrees and prune review refs #2623

Closed

Description

@codeforester

Goal

Keep PR-review checkouts detached and separate from ordinary issue branches, with an explicit safe cleanup command for review worktrees and their local refs.

Background

Review tooling currently fetches PR heads into local refs/heads/pr-* branches such as pr-2621 and pr-2621-check2. These are local-only scratch refs, not GitHub branches, but they accumulate in the normal branch inventory and cannot be safely classified by basectl gh branch prune.

The active GitHub branch-name ruleset and basectl gh pr create correctly protect repository implementation branches, but neither can intercept arbitrary local git fetch ...:<ref> operations.

Scope

  • Add a Base-owned review checkout workflow that fetches PR heads into a namespaced local ref such as refs/base-review/pr/<number>/<slug>.
  • Create detached worktrees under <repo>-review-worktrees/pr-<number>-<slug>.
  • Store review metadata outside the worktree under the Git common directory.
  • Add basectl gh review fetch with safe PR, slug, path, and refresh validation.
  • Add basectl gh review prune, dry-run by default, with explicit handling for merged, open, closed-unmerged, dirty, missing, orphaned, and stale review checkouts.
  • Update command reference, GitHub workflow documentation, help, completions, and focused tests.

Acceptance Criteria

  • The review fetch path creates no refs/heads/pr-* branch.
  • Created review worktrees are detached and use the documented path convention.
  • Review metadata records the repository, PR number, slug, review ref, head SHA, path, and timestamps outside the worktree.
  • basectl gh review prune is dry-run by default and never removes dirty, open-PR, unowned, or mismatched worktrees without an explicit supported scope.
  • Applied pruning removes the worktree, namespaced review ref, and metadata as one reported operation.
  • Tests cover path traversal, naming, detached state, dirty worktrees, PR states, stale heads, orphaned metadata/refs, and idempotent cleanup.
  • Documentation explains that legacy pr-* branches are a separate one-time cleanup and are not handled automatically by the new pruner.

Non-Goals

  • Do not change the canonical issue branch naming convention.
  • Do not make the normal branch or worktree pruners delete no-PR branches.
  • Do not add a permanent legacy-review feature; existing legacy refs are a one-time cleanup.

Validation

bats cli/bash/commands/basectl/tests/gh-review.bats
shellcheck <changed shell files>
git diff --check
env -u BASE_HOME ./bin/base-test

Project Fields

  • Status: Backlog
  • Priority: P2
  • Area: CLI
  • Initiative: Agentic Coding Platform
  • Size: M
  • Milestone: v1.13.0
  • Category: enhancement

Agent Assignment

Assignee: codeforester. Use an issue-backed worktree. The legacy pr-* refs are not part of this implementation and should not be auto-deleted by the new command.

Activity

  1. self-assigned this
    on Oct 20, 2026
  2. moved this from Backlog to In Progress in baseon Oct 20, 2026
  3. moved this from In Progress to In Review in baseon Oct 20, 2026
  4. added this to the v1.11.0 milestone on Oct 21, 2026
  5. added a commit that references this issue on Oct 21, 2026
    f63551f
  6. moved this from In Review to Done in baseon Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or product improvement

Type

No type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions