Skip to content

status: the third layer — a fork against what it was forked from, via a remote named upstream or, under --fetch, one read-only gh api question - #11

Merged
brettheap merged 10 commits into
mainfrom
feat/status-fork-upstream
Sep 11, 2026
Merged

brettheap merged 10 commits into
mainfrom
feat/status-fork-upstream

Conversation

@brettheap

@brettheap brettheap commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Ruling: Brett Heap, 2026-09-11, verbatim: "next layer: fork against upstream" — the third of the layers named when status landed (#9), after the local one and --fetch (#10).

Stacked on #10 (feat/status-fetch), on #9, on #8; the base is #10's branch and this carries only the fork layer on top.

What it reads

When origin is a FORK, the one question a clone cannot answer about itself is whether the fork has kept up with what it was forked from: a fork's main falls behind quietly, and a feature cut from it is a feature cut from stale ground. Two ways to know, in order:

1. A remote named upstream — the convention every fork guide teaches — read from LOCAL refs, origin/<branch> against upstream/<branch>, as of the last fetch. No network.

  root   main   ~/projects/Atlas
    - fork: origin/main is 1 commit(s) behind upstream/main, as of the last fetch

Ahead is a finding too (origin/main has N commit(s) upstream/main does not: somebody pushed to the fork's main instead of opening a pull request). Never fetched: fork: no upstream/main here: the upstream remote was never fetched (--fetch asks it). With --fetch the upstream remote is fetched as well, on its own line (fetched upstream: upstream/main is here now, at …), under the same pinned refspec, so the write stays under refs/remotes/.

2. With no such remote, and only under --fetch — the one flag that reaches the network — an origin whose configured URL is on github.com is asked about with gh api repos/<owner>/<name>, read-only:

    - fork of opensoft/Atlas (per GitHub), and no remote named upstream here: `git remote add upstream https://github.com/opensoft/Atlas.git` reads the drift locally
    - fork: origin/main is 3 commit(s) behind opensoft/Atlas's main (per GitHub)
    - fork: origin/main has 1 commit(s) opensoft/Atlas's main does not (per GitHub)

GitHub's compare endpoint gives the counts once (per_page=1, the totals are totals regardless). The git remote add upstream … is named, never run: from then on the drift reads from local refs. gh absent, or failing (not logged in, a private parent), is said ONCE per run under the first row that asked, not repeated per repository. Not a fork: nothing to say — most estates are the organisation's own repositories. Not github.com: never asked. The origin URL is read from config, not remote get-url, so a url.<base>.insteadOf rewrite cannot hide whose repository it is.

fetch_origin becomes fetch_remote <repo> <branch> <remote>, with the remote's name in every line it prints and in its refspec.

--refmap, and a hole in #10's bound

Found while building the upstream fetch: a refspec on the command line bounds what is fetched and pruned, but git still maps every ref it fetched through the CONFIGURED refspecs as well — "opportunistic remote-tracking updates". Under a mirror-style remote.<name>.fetch, the pinned fetch alone moved a detached leg's local main (proved: 6fb2a82 -> 49184cc with the pinned refspec; unchanged with --refmap), and in a checked-out root it refused outright (refusing to fetch into branch 'refs/heads/main' checked out at …). --refmap (git 2.1) with the same refspec replaces the configured mapping for the one fetch, so nothing outside refs/remotes/<remote>/ is written by either route.

The fix is landed at its source, on #10's branch (commit b01a16a, with the test that should have caught it now asserting the leg's local main did not move), and this branch is rebased on top; here it applies to the upstream fetch as well.

Hygiene

The rule "no gh api in an estate command" now allows exactly one: inside ask_github_fork, and nowhere else in status (the usage prose that names it is set aside as prose). park and resume still call no API. The document test additionally holds "upstream" and "gh api" in README, AGENTS.md and the command's header.

Docs

README.md 214 -> 221, AGENTS.md 117 -> 122, caps raised in dated entries. AGENTS.md rule 4 now says how a fork is read, that this is the ONE use of gh in these commands and it is read-only, and that the git remote add upstream … a finding names is the person's to run.

Tests

197 -> 202. New: a fork behind its upstream remote from local refs, before and after the remote is fetched; --fetch fetching upstream under the pinned refspec with a mirror config, the local main unmoved; a fork pushed ahead of its parent; a github.com origin asked only under --fetch, with a FAKE gh first on PATH answering the two calls the command makes (fields joined by 0x1F, every call logged) and a url.<base>.insteadOf rewrite so an origin that looks like github.com still fetches from a bare on disk — the three calls and their order are asserted; a failing gh said once across two github rows, and a local-path origin never asked. Nothing reaches the network.

bash -n status passes; shellcheck status reports only SC2317. python3 -m pytest tests -q: 202 passed locally with the submodule initialised, on the tree rebased onto #10 after the --refmap fix.

Not merged

Opened for review, stacked on #10 on #9 on #8. A review of this layer was still running when it was opened; anything it finds lands as a follow-up commit here.

🤖 Generated with Claude Code

Summary by Sourcery

Add the fork layer to status by reporting divergence from an upstream remote or, when fetching GitHub repositories, their configured parent.

New Features:

  • Add fork status reporting by comparing a fork’s origin branch with a fetched remote named upstream.
  • Under --fetch, identify GitHub fork relationships and report parent-branch divergence through read-only GitHub CLI queries when no upstream remote exists.

Bug Fixes:

  • Ensure fork fetching is confined to remote-tracking refs even when configured remotes use mirror-style refspecs.

Enhancements:

  • Extend status findings to cover both fork lagging behind its parent and fork commits absent from the parent.
  • Report missing upstream refs, fetch results, GitHub query failures, and suggested upstream configuration without repeating failures across repositories.

Documentation:

  • Document fork detection, upstream handling, and the single read-only GitHub CLI use in README.md and AGENTS.md.

Tests:

  • Add coverage for local upstream comparisons, upstream fetching, ahead and behind forks, GitHub fallback queries, failure deduplication, URL rewriting, and non-GitHub origins.

Chores:

  • Update repository hygiene checks and documentation line limits for the new status behavior.

brettheap and others added 8 commits September 10, 2026 22:04
… `park --all` / `-a` is the sweep unasked

Brett Heap's RULING of 2026-09-10, verbatim: "lets change that so it parks
the current repo. if not in a repo, then asks if want to park all. and park
all should be park -a or park --all." It supersedes his openRepoShape #91
ruling of the same day, under which bare `park` with no estate around the
cwd parked every estate unasked.

- The walk-up is unchanged: inside an estate, bare `park` parks that one.
- Outside every estate, at a terminal: list, then `park every estate
  above? [y/N]` on stderr. Only y/yes runs #91's sweep; anything else
  exits 2 with "nothing was parked".
- Outside every estate, with no terminal on stdin: refuse, list, and name
  `--all`. Never hang on a question nobody can see.
- `park --all` / `park -a`: the sweep from anywhere, unasked. Refused
  alongside <Name> or --repo, and when no estate exists at all.
- `resume --all` / `-a` refuses by name and says why `resume` has no
  sweep, instead of the generic "put it after `--`".
- The sweep itself (name order, continue past a refusal, skip roots
  without the overlay, one summary) is untouched; it now takes its rows
  from the caller that listed them.

Tests 147 -> 160: the question under a real pseudo-terminal (y/Y/yes/YES,
Enter/n/no/other), the no-terminal refusal, --all and -a, --all from
inside an estate, the flag conflicts, and the sweep tests now driven by
--all. README 178 -> 182 and AGENTS.md 95 -> 99, caps raised in dated
docstring entries.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…f sync across an estate, read-only, as of the last fetch

Brett Heap's RULING of 2026-09-10, verbatim: "lets go with a fourth file.
start with the local status layer."

`status [<Name>] | --all` finds the estate exactly as `park` and `resume`
do — the shared resolver block is now carried byte for byte by three files —
and then only READS: for the holder or root, each member's working clone
and every mounted leg, whether the tracking branch is ahead of or behind its
origin, what is dirty or stashed, a root off its tracking branch or detached,
feature branches never pushed or whose remote branch is gone, dirty feature
worktrees, a leg checked out away from its pin or pinned behind its origin
or on an unpushed leg commit, a leg on a feature branch, a leg declared and
not mounted, and a member with no working clone. It fetches nothing, says
"as of the last fetch" on every run, and takes no lock
(`git --no-optional-locks`). Exit 0 in sync, 1 findings printed, 2 refused.
Bare `status` inside an estate reads that one; outside every estate it reads
them all WITHOUT asking, because nothing writes; `--fetch` refuses by name
as the next layer.

- `openRepoTools --install` places FOUR files; the count line says `4 of 4`.
- README and AGENTS.md (new rule 4) document it; caps raised in dated entries.
- CI parses the fourth file with /bin/bash -n.
- `park` and `resume` change only in comments: the shared block now says
  three copies.

An independent review of the first draft (14 synthetic estates, a full-tree
snapshot proving nothing is written) found six things, all fixed here: a git
that cannot run is refused rather than reported as an empty estate; the one
unguarded pipeline; 0x1F rather than TAB between for-each-ref fields so an
empty field cannot shift; "0 commit(s) never pushed" reworded; a missing flag
value exits 2 in the command's own words, not bash's exit 1; a valueless
.gitmodules key no longer invents a leg. Plus the gap it flagged: a leg on a
feature branch at its pin is a finding, as AGENTS.md rule 1 already names it.

Tests 160 -> 187: a new tests/test_status_command.py (22, real bare remotes
and a leg submodule, one scenario each), the installer and hygiene suites
taught the fourth file, and the resolver identity held three ways.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…rite bounded to remote-tracking refs by a pinned refspec

Brett Heap's RULING of 2026-09-11, verbatim: "next layer: --fetch".

With the flag, `git fetch --quiet --prune --recurse-submodules=no origin
'+refs/heads/*:refs/remotes/origin/*'` runs in every repository before it
is read — holder or root, each member's working clone, every mounted leg —
so the ahead/behind answers are current and a remote branch deleted under a
feature reads as gone. One line under each row says what the fetch did:
which ref moved and from where, nothing new, or that the tracking branch is
GONE from origin. A fetch that fails is a finding on that row and the row is
read as of the last fetch that worked; a repository whose gitfile points at
a deleted git dir is reported as unreadable, not as "no remote". The footer
names the one write. Without the flag nothing changes.

THE REFSPEC IS PINNED ON THE COMMAND LINE, and that is what bounds the
write. The review of this layer deleted a local branch through the
configured form: a leg whose `remote.origin.fetch` maps heads onto local
branches, plus `--prune`, loses a branch origin no longer has, and
`fetch.pruneTags` set globally prunes local tags the same way — while the
report calls the repository clean. Naming `+refs/heads/*:refs/remotes/origin/*`
means the only refs that can move or go are under `refs/remotes/origin/`,
whatever the config says; a test holds that with both misconfigurations set.

`GIT_TERMINAL_PROMPT=0` makes an https credential prompt fail and be
reported; an ssh host-key or passphrase prompt is ssh's own and still
blocks, which the header, usage, README and AGENTS.md now say. The docs say
exactly what a fetch writes: remote-tracking refs, the objects behind them
and FETCH_HEAD — never a local branch, tag, HEAD, index or working tree.

Tests 187 -> 197: behind is seen in one run and the fetch persists; local
branches, HEAD, index, working tree and stash are untouched while origin/main
moves; a branch deleted from another clone reads as gone after the prune; a
dead URL is a finding and the leg is still fetched; the leg is fetched on its
own row; no origin is a finding; `--all --fetch` fetches every estate; the
pinned refspec keeps a local branch and tags under a mirror refspec and
pruneTags; a renamed default branch reads as GONE; a dangling gitfile is
named as such. One assertion that could never fail is now real. README 203
-> 214, AGENTS.md 111 -> 117 (rule 4: `status --fetch` is the one way it
reaches the network), caps raised in dated entries.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… a local branch through the pinned fetch

A refspec on the command line bounds what is fetched and pruned, but git
still maps every ref it fetched through the CONFIGURED refspecs as well —
"opportunistic remote-tracking updates". Under a mirror-style
`remote.origin.fetch` the pinned fetch alone moved a detached leg's local
`main` (proved: 6fb2a82 -> 49184cc with the pinned refspec, unchanged with
`--refmap`), and in a checked-out root it refused outright. `--refmap` (git
2.1) with the same refspec replaces the configured mapping for this one
fetch, so nothing outside `refs/remotes/origin/` is written by either route.
The test that should have caught it now asserts the leg's local `main` did
not move.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ia a remote named `upstream` or, under `--fetch`, one read-only `gh api` question

Brett Heap's RULING of 2026-09-11, verbatim: "next layer: fork against
upstream".

When origin is a FORK, the one question a clone cannot answer about itself
is whether the fork has kept up with what it was forked from. Two ways to
know, in order:

1. A remote named `upstream` — the convention every fork guide teaches — is
   read from LOCAL refs: `origin/<branch>` against `upstream/<branch>`, as
   of the last fetch. Behind is a finding ("sync the fork"); ahead is a
   finding (commits on the fork's main the parent does not have). With
   `--fetch` the upstream remote is fetched too, on its own line, under the
   same pinned refspec. Never fetched: a finding that names `--fetch`.
2. With no such remote, and only under `--fetch` — the one flag that
   reaches the network — an origin whose configured URL is on github.com is
   asked about with `gh api repos/<owner>/<name>`, read-only. A fork is a
   finding naming the parent and the `git remote add upstream …` that makes
   the drift readable locally from then on, and GitHub's compare endpoint
   gives the counts once. `gh` absent or failing is said ONCE per run, not
   per row. Not a fork: nothing to say. Not github.com: never asked.

`fetch_origin` becomes `fetch_remote <repo> <branch> <remote>`, printing the
remote's name in every line.

--refmap, and a hole in #10's bound. A refspec on the command line bounds
what is fetched and pruned, but git still maps every fetched ref through the
CONFIGURED refspecs as well ("opportunistic remote-tracking updates"): under
a mirror-style `remote.<name>.fetch` the pinned fetch alone moved a detached
leg's local `main`, and refused outright in a checked-out root. `--refmap`
(git 2.1) with the same refspec replaces the configured mapping for the one
fetch, so nothing outside `refs/remotes/<remote>/` is written by either
route. The test that should have caught it now asserts the leg's local
`main` did not move.

The hygiene rule "no `gh api` in an estate command" now allows exactly one:
inside `ask_github_fork`, and nowhere else in `status`; the verbs still
call no API. Tests 197 -> 202: a fork behind its upstream remote from local
refs, before and after the remote is fetched; `--fetch` fetching upstream
under the pinned refspec with a mirror config; a fork pushed ahead of its
parent; a github.com origin asked only under `--fetch`, with a fake `gh`
answering the two calls and a `url.<base>.insteadOf` rewrite so the fetch
still comes from a bare on disk; a failing `gh` said once, and a local-path
origin never asked. README 214 -> 221, AGENTS.md 117 -> 122, caps raised in
dated entries.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 11, 2026 02:26
@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

status now reports whether fork branches have diverged from their parent, using locally fetched upstream refs when available and a single read-only GitHub API fallback only with --fetch; fetches are safely constrained with --refmap, and comprehensive tests, hygiene rules, and documentation cover the new behavior.

Sequence diagram for fork status resolution

sequenceDiagram
    participant Status
    participant GitRefs
    participant GitHub
    participant Gh

    Status->>GitRefs: Read origin/<branch> and upstream/<branch>
    alt upstream refs available
        GitRefs-->>Status: Compare local fork and parent refs
    else --fetch and no upstream remote
        Status->>GitHub: Read origin URL config
        alt github.com origin
            Status->>Gh: gh api repos/<owner>/<name>
            Gh-->>Status: Parent repository and compare totals
        else non-GitHub origin
            GitHub-->>Status: No API request
        end
    end
    Status-->>Status: Report fork drift or missing upstream guidance
Loading

Sequence diagram for safe upstream fetching

sequenceDiagram
    participant Status
    participant Git
    participant Refs as RemoteTrackingRefs

    Status->>Git: fetch_remote <repo> <branch> upstream
    Git->>Refs: Fetch with pinned refspec and --refmap
    Git-->>Status: upstream/<branch> updated
    Status-->>Status: Compare origin/<branch> with upstream/<branch>
Loading

Flow diagram for fork status source selection

flowchart TD
    A[Origin is a fork] --> B{Remote named upstream?}
    B -->|Yes| C[Read origin/<branch> and upstream/<branch> locally]
    B -->|No| D{--fetch enabled?}
    D -->|No| E[Report missing upstream ref]
    D -->|Yes| F{Origin URL is github.com?}
    F -->|No| G[Do not ask GitHub]
    F -->|Yes| H[Call gh api once]
    C --> I[Report behind or ahead drift]
    H --> I
    E --> J[Name git remote add upstream guidance]
    G --> J
Loading

File-Level Changes

Change Details Files
Add fork-parent drift reporting to status, preferring local upstream refs and falling back to a guarded GitHub comparison.
  • Compare origin/<branch> with upstream/<branch> when the named remote exists, including behind, ahead, and never-fetched findings.
  • Under --fetch, fetch upstream with the pinned remote-tracking refspec and report the fetch result.
  • When no upstream exists, query GitHub only for github.com origins and only under --fetch; report the parent, compare counts, suggested remote, and one-run failures.
  • Preserve URL-based GitHub identification despite insteadOf rewrites and avoid querying non-fork, non-GitHub, or local-path repositories.
status
Bound all fetch mappings to remote-tracking refs so configured mirror-style refspecs cannot modify local branches.
  • Replace the origin-specific fetch helper with a remote-parameterized helper.
  • Apply --refmap alongside pinned refspecs for both origin and upstream fetches.
  • Add regression coverage ensuring local branches remain unchanged while upstream refs are fetched.
status
tests/test_status_command.py
Expand tests and repository hygiene checks for the fork layer and its single permitted API call.
  • Test local upstream drift before and after fetching, fork-ahead findings, GitHub compare behavior, failure deduplication, call ordering, and non-GitHub suppression.
  • Use a fake gh and URL rewrite to verify all behavior without network access.
  • Allow gh api only inside ask_github_fork while continuing to prohibit it in other estate commands.
tests/test_status_command.py
tests/test_repo_hygiene.py
Document fork status semantics, fetch behavior, and the restricted GitHub integration.
  • Describe the upstream-first decision path, --fetch requirements, read-only API usage, and suggested git remote add upstream command.
  • Update dated documentation line-count limits and assertions.
README.md
AGENTS.md
tests/test_repo_hygiene.py
tests/test_status_command.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. With --fetch, the command now contacts GitHub through gh and writes upstream remote-tracking refs and fetched objects, so a wrong comparison or fetch can leave bounded repository state behind after a revert. Those refs and objects can be removed or the fetch rerun, and the change does not move money, alter access, delete records, or make irreversible production changes.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Address the critical GitHub host-validation issue and the remaining fetch-state/reporting inconsistencies.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Extends status with fork-drift checks against local upstream refs or GitHub under --fetch.

Changes:

  • Adds safe upstream fetching and ahead/behind reporting.
  • Adds GitHub fork detection and comparison.
  • Expands tests, hygiene checks, and documentation.
File summaries
File Reviewed changes
tests/test_status_command.py Covers upstream refs, safe fetching, GitHub fallback, failures, and URL rewriting.
tests/test_repo_hygiene.py Updates hygiene and documentation assertions.
status Implements upstream and GitHub checks. Findings: critical (3 votes) GitHub host validation; moderate (2 votes) failed-fetch state; moderate (1 vote) repeated GitHub failures; nit (3 votes) safety comment; nit (1 vote) ambiguous fetch error.
README.md Documents fork-status behavior and upstream guidance.
AGENTS.md Updates operational guidance for fork checks and read-only GitHub usage.
Review details

Suppressed comments (2)

status:990

  • If the first repository is identified as a fork but its compare request fails (for example because the parent is private), this branch reports the failure but leaves GH_STATE=ok. Every later GitHub fork will invoke gh again and repeat the failure, contrary to the documented once-per-run handling; mark the GitHub state failed here so subsequent rows are suppressed.
    else
        cmp="${cmp%%$'\n'*}"
        finding "fork: could not compare origin/$branch with $parent's $parent_default: ${cmp:-no message}"

status:854

  • Since this function now handles both origin and upstream, this early failure message still says only fetch: and omits $remote; it violates the function's own contract that every fetch line names the remote and becomes ambiguous when diagnosing upstream fetches. Include the remote name here and update the corresponding assertion.
        finding "fetch: not a readable git repository (a gitfile whose gitdir is gone?), so nothing could be fetched"
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread status
local repo="$1" branch="$2" url slug owner info is_fork parent parent_default cmp behind ahead
url="$(g "$repo" config --get remote.origin.url 2>/dev/null || true)"
case "$url" in
*github.com*) ;;
Comment thread status
if [ "$UPSTREAM_FETCHED_OK" -eq 1 ]; then
finding "fork: no upstream/$branch after the fetch: upstream has no branch $branch"
else
finding "fork: no upstream/$branch here: the upstream remote was never fetched (\`--fetch\` asks it)"
Comment thread status
# the objects behind them and `FETCH_HEAD`, and nothing else: no branch, no
# tag, no HEAD, no index, no working tree, because the refspec is pinned on
# the command line rather than trusted from config (see `fetch_origin`).
# the command line rather than trusted from config (see `fetch_remote`).
@brettheap
brettheap changed the base branch from feat/status-fetch to main September 11, 2026 02:40
…am, so this PR's diff is its own change

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants