Skip to content

emrg: the API sync moves the refs and leaves the working tree on the old commit #2939

Closed

Description

@pm25coder

scripts/sync-master-from-api.py fetches a branch over the Git Data API when git-over-https is down. It ends by moving refs/heads/<branch> and refs/remotes/origin/<branch> with git update-ref, prints one line saying so, and exits 0.

It never touches the index or the working tree, and it never says that it did not.

What was observed

Measured on a checkout at d1d9ecad while https://github.com was returning Recv failure: Connection was reset:

$ uv run --no-sync python3 scripts/sync-master-from-api.py
remote argszero/emrg master head: 42bf1cc
  + 42bf1cc (argszero, emrg: bump version to 0.3.58 (#2938))
  + 9466c2d (pm25coder, emrg: report a prose-named issue as unpaired, not as absent )
  ...
updated refs/heads/master and refs/remotes/origin/master -> 42bf1cc

Exit 0, and the next readings disagree with each other:

$ git log --oneline -1
42bf1cc1 emrg: bump version to 0.3.58 (#2938)

$ grep __version__ emrg/__init__.py
__version__ = "0.3.57"

$ git show HEAD:emrg/__init__.py | grep __version__
__version__ = "0.3.58"

$ git status --short | head -3
M  emrg/__init__.py
M  emrg/gui/package-lock.json
M  emrg/gui/package.json

Ten tracked files read as staged modifications: the index still held the previous commit's tree, and the working tree with it. git reset --hard HEAD was what put the two in step; nothing the tool printed suggested it was needed.

Why it matters

Everything a cycle reads after the sync is about the old tree while git log answers about the new one. In the same run that produced the output above, the version file read 0.3.57 on a tree whose HEAD declared 0.3.58 — the same confusion scripts/check-release-tag.py exists to catch, arriving through a different door. This repo's own rule is that a reading names the tree it read; a tool that moves the tree and stays silent leaves the reader holding the previous one, and no guard downstream can tell.

The failure is quiet in the worst way: the refs are correct, so git log, git rev-parse HEAD and git show HEAD:<path> all answer about the new commit, while read, grep and any command that opens a file answer about the old one. Only a comparison of the two notices.

What the fix must satisfy

  1. After the refs move, the run says whether the index and working tree now match the new commit, before it exits 0 — one line, near the updated refs/... line.
  2. When they do not match, it prints the command that brings them into step and warns that the command discards local edits — and it does not run that command. A tool that reset a worktree on its own would destroy a caller's uncommitted work, which is worse than the silence it replaces.
  3. A run that moved no ref prints no such line. --ref <sha> materializes a commit and deliberately creates no branch; a failure stops with "no refs touched". Neither has a new commit for a worktree to be in step with.
  4. "Could not measure" is its own answer, never a match. A git invocation that fails to answer is reported as unmeasured, not as agreement.
  5. A test holds both directions: a moved ref with a worktree on the previous commit reports the mismatch and the remedy; a moved ref with a matching worktree reports the match. The test must not need a network call or a real remote.

Acceptance

On a clean checkout the tool's final line states that the working tree matches the new commit. On a checkout whose index sits on the previous commit the same line states the mismatch and names the remedy, and the checkout is left exactly as it was found.

Activity

  1. pm25coder commented on Nov 17, 2026

    @pm25coder
    CollaboratorAuthor

    Handled by #2940

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions