Repository navigation
fix(minimald): leave HEAD alone when a push targets another branch - #2319
Merged
norrietaylor merged 5 commits intoOct 18, 2026
Merged
norrietaylor merged 5 commits into
norrietaylor merged 5 commits into
Conversation
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>
Contributor
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.
Member
|
/review |
Contributor
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.
Member
|
/review |
norrietaylor
approved these changes
Oct 18, 2026
Member
There was a problem hiding this comment.
Approved on ARCH PASS at 6b3f7a1.
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)
Merged
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Routing-Key: inbox-route/I_kwDOSUhdos8AAAABX3veMQ
git push (redacted) <branch>checked out every pushed branch inthe 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_receivenow records thechecked-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 --checkcargo clippy --workspace --all-targets --locked -- -D warningscargo test --locked -p minimal --test git_remote— 2/2 passcargo test --locked -p minimald --lib exec::— 50/50 passcargo test --locked -p minimald -p minimalfull suites show onlyfailures identical on pristine
mainin this sandbox(net::switch/answerer/connection/rpc + one legacy-network-spelling
unit test) — pre-existing environment limits, untouched by this diff
with the fix
Summary by CodeRabbit
HEADbranch when it is pushed, or the first pushed branch otherwise.HEADis detached. In the latter case, a notice explains how to switch to a branch.HEADare handled.