8000 fix(minimald): leave HEAD alone when a push targets another branch by gominimal-aw-bot[bot] · Pull Request #2319 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(minimald): leave HEAD alone when a push targets another branch - #2319

Merged
norrietaylor merged 5 commits into
mainfrom
inbox-patch/fix-git-push-other-branch-checkout-c1d8548b46a15dc7
Oct 18, 2026
Merged

norrietaylor merged 5 commits into
mainfrom
inbox-patch/fix-git-push-other-branch-checkout-c1d8548b46a15dc7

Conversation

@gominimal-aw-bot
@gominimal-aw-bot gominimal-aw-bot Bot commented Oct 18, 2026 •
Copy link
Copy Markdown
Contributor

Routing-Key: inbox-route/I_kwDOSUhdos8AAAABX3veMQ

git push (redacted) <branch> checked out every pushed branch in
the session workspace, so pushing any branch other than the current one
silently moved the session's HEAD and swapped the worktree to it.

The post-receive hook in handle_git_receive now records the
checked-out branch and whether HEAD is born before the ref loop; a
push to a non-checked-out branch only moves the ref (receive-pack
already did that), while the still-unborn first push keeps populating
the worktree as before (informed by #347).

Verification

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo test --locked -p minimal --test git_remote — 2/2 pass
  • cargo test --locked -p minimald --lib exec:: — 50/50 pass
  • cargo test --locked -p minimald -p minimal full suites show only
    failures identical on pristine main in this sandbox
    (net::switch/answerer/connection/rpc + one legacy-network-spelling
    unit test) — pre-existing environment limits, untouched by this diff
  • New regression test verified red against the unfixed hook and green
    with the fix
  • live-session: native-daemon-e2e — runs on this PR

Summary by CodeRabbit

  • New Features
    • Pushes to an empty workspace check out the existing HEAD branch when it is pushed, or the first pushed branch otherwise.
    • Pushes update refs without changing the worktree when targeting another branch or when HEAD is detached. In the latter case, a notice explains how to switch to a branch.
  • Bug Fixes
    • A failed initial checkout due to local files is reported while pushed refs are still updated.
  • Documentation
    • Clarified checkout behavior after pushes, including how dirty worktrees and detached HEAD are handled.

The post-receive hook checked out every pushed branch, so pushing a
branch other than the workspace's current one moved HEAD and swapped
the worktree to it. Capture the checked-out branch and HEAD's
born/unborn state up front; a push to a non-checked-out branch now
only moves the ref (receive-pack already did that), while the
still-unborn first push keeps populating the worktree as before.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gominimal-aw-bot
gominimal-aw-bot Bot requested a review from a team as a code owner October 18, 2026 03:40
@gominimal-aw-bot gominimal-aw-bot Bot added the agent:fix Agentic fix PR eligible for review iteration; min-aw's worker-iterate gates on it. label Oct 18, 2026
@coderabbitai
coderabbitai Bot commented Oct 18, 2026 •
Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: aa053c78-dab9-4048-b74e-7813ed098053
📥 Commits

Reviewing files that changed from the base of the PR and between 11b0b44 and 6b3f7a1.

📒 Files selected for processing: 3
  • crates/minimal/tests/git_remote.rs
  • crates/minimald/src/exec.rs
  • docs/reference/cli-min.md

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 0 remain after this review.

📝 Walkthrough

The post-receive hook now updates pushed refs while limiting checkout to eligible branches. It preserves the worktree for pushes to other branches and detached HEAD, and reports when detached HEAD prevents checkout. Integration tests and CLI documentation cover these cases.

Changes: Push checkout behavior

Layer / File(s) Summary
Post-receive checkout rules
crates/minimald/src/exec.rs
The hook checks whether HEAD is unborn, attached, or detached when processing pushed refs. It checks out the eligible branch and reports when refs move while HEAD is detached.
Push scenarios and documented behavior
crates/minimal/tests/git_remote.rs, docs/reference/cli-min.md
Integration tests cover separate and combined pushes, initial checkout, and detached HEAD. The CLI reference describes the corresponding checkout behavior.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Git
  participant Hook as post-receive hook
  participant Refs as Git refs
  participant Worktree
  Git->>Hook: deliver pushed ref updates
  Hook->>Refs: advance pushed refs
  Hook->>Worktree: check out an eligible branch
  Hook-->>Git: report detached HEAD when refs move without checkout
Loading

Suggested reviewers: norrietaylor

Merge Risk: ⚪ Minimal · up to 6b3f7

Pushes to branches other than the checked-out one now leave the session's HEAD and worktree alone, and detached HEAD pushes report that refs moved without checkout. No merge-blocking risk remains in the supplied evidence.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing pushes to another branch from moving the current HEAD.
Description check Passed The description explains the behavior change and provides detailed verification commands and results. It does not include the template's Checklist section, but the required summary and testing informa…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the behavior change and provides detailed verification commands and results. It does not include the template's Checklist section, but the required summary and testing information are present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Vale (3.23.0)

{
"Line": 0,
"Path": "",
"Text": "E100 [loadStyles] Runtime error\n\nstyle 'ste' does not exist on StylesPath\n\nExecution stopped with code 1.",
"Code": "E100",
"Span": 0
}

A rabbit watches branches hop,
The first eligible branch takes its spot.
Other refs advance along,
The worktree stays where it belongs.
Detached HEAD gets a notice from the burrow.

Comment @coderabbitai help to get the list of available commands.

@norrietaylor norrietaylor changed the title fix: fix(minimald): leave HEAD alone when a push targets another branch fix(minimald): leave HEAD alone when a push targets another branch Oct 18, 2026
@gominimal-aw-bot gominimal-aw-bot Bot added the agent:resolve Consent gate: pr-conflict-resolver may rewrite this branch label Oct 18, 2026
A first push carrying several branches checked each one out in turn,
so HEAD ended on the last. Record the checkout so later refs in the
same push only move their refs, and cover a multi-ref push that
includes the current branch.
…e born flag

A first push into a fresh workspace that carries two branches checks out
only the first, and every multi-ref test now checks the other ref lands
at the pushed tip. The hook's HEAD flag is a string (born=yes) instead of
a raw exit status, and its header comment now matches the
first-checkout-wins behaviour.
@norrietaylor
Copy link
Copy Markdown
Member

/review

@minimal-foundry
minimal-foundry Bot commented Oct 18, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at 6b3f7a14b790.

Nothing to do.

Clobber: none: git log on exec.rs shows this PR is the current series (11cd1c7, 011f3fa, bb80b12, 6b3f7a1); no prior fix is reverted.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

Comment thread crates/minimald/src/exec.rs Resolved
A detached HEAD in the session worktree matches no branch, so the
post-receive hook moves the pushed refs and never checks anything out.
That is intended, and matches plain git, but it happened silently.

The hook now prints one stderr line, which the pusher sees as a
`remote:` line, naming the detached HEAD and the `git switch` that
re-attaches it. A new git_remote test detaches the workspace HEAD,
pushes, and checks the message, the still-detached HEAD and the moved
ref. The cli-min push paragraph covers the detached case and corrects
which branch the first push into an empty workspace checks out.
@norrietaylor
Copy link
Copy Markdown
Member

/review

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minimal-review — approved

Verdict APPROVE — No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 18, 2026
@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved on ARCH PASS at 6b3f7a1.

@norrietaylor
norrietaylor added this pull request to the merge queue Oct 18, 2026
Merged via the queue into main with commit 0a297d0 Oct 18, 2026
36 checks passed
@norrietaylor
norrietaylor deleted the inbox-patch/fix-git-push-other-branch-checkout-c1d8548b46a15dc7 branch October 18, 2026 20:30
norrietaylor pushed a commit that referenced this pull request Nov 4, 2026
…2319)

The post-receive hook checked out every pushed branch, so pushing a branch other than the
workspace's current one moved HEAD and swapped the worktree to it. A push to a non-checked-out
branch now only moves the ref. A first push into a fresh workspace checks out the first branch
and leaves the rest as refs, and a push onto a detached HEAD says so on a remote: line with the
git switch that re-attaches it. The cli-min push paragraph describes all three.

Backport of #2319. Applied without adaptation.

(cherry picked from commit 0a297d0)
norrietaylor pushed a commit that referenced this pull request Nov 5, 2026
…2319)

The post-receive hook checked out every pushed branch, so pushing a branch other than the
workspace's current one moved HEAD and swapped the worktree to it. A push to a non-checked-out
branch now only moves the ref. A first push into a fresh workspace checks out the first branch
and leaves the rest as refs, and a push onto a detached HEAD says so on a remote: line with the
git switch that re-attaches it. The cli-min push paragraph describes all three.

Backport of #2319. Applied without adaptation.

(cherry picked from commit 0a297d0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:fix Agentic fix PR eligible for review iteration; min-aw's worker-iterate gates on it. agent:resolve Consent gate: pr-conflict-resolver may rewrite this branch review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0