Repository navigation
Keep default-branch commits out of pre-push reviews after a merge or rebase - #92
Open
Utkarsh-Srivastava29 wants to merge 7 commits into
Open
Utkarsh-Srivastava29 wants to merge 7 commits into
Utkarsh-Srivastava29 wants to merge 7 commits into
Conversation
…rebase The pre-push hook compared each updated branch with the commit the remote had. Once the branch merged or rebased onto newer default-branch commits, that diff also carried those commits, so the push review included other people's already-merged changes: credits spent on code already reviewed, findings in code the push did not add, and larger patches more likely to come back incomplete. The remote's commit stays the base while the branch takes in nothing new from the default branch, so ordinary pushes still review only what they add. Otherwise the branch is compared with its merge-base with the default branch, as a new branch already is. A remote commit missing from the checkout falls back the same way instead of failing the diff.
…lt branch A branch with no history in common with the default branch, such as gh-pages, has no merge-base with it. `git merge-base` then exits 1, which the pre-push base selection treated as a failure, so the push printed as not reviewed where it was reviewed against the remote's commit before. Exit status 1 now means "no common ancestor", and the remote's commit stays the base. The amend case of the regression test now also checks that a patch against the remote's commit holds only the change to it, and that a patch against a merge-base adds the whole file. Both found by a Proofline review of this change.
A push to the default branch itself compared its tip with this checkout's tracking ref for that branch. When the remote's default branch had been rewound and the push restored the commit the stale tracking ref still held, the merge-base was the pushed commit, so the hook found nothing to review and let the push through even with onIncomplete=block. The hook now keeps the destination ref from Git's input, and an update of the remote's default branch is compared with the commit the remote advertises, as before this change. The base-selection tests now push a branch that is not checked out, so a base read from HEAD instead of the pushed commit fails them. Both found by a second Proofline review of this change.
The merge-base with the tracking ref of the default branch is only a better base than the remote's commit when it leaves out commits the remote already has. A stale tracking ref breaks that. When the remote rewound a branch and the push restored a commit the tracking ref still held, the merge-base was the pushed commit itself, so the hook found nothing to review and let the push through. A destination that is not a branch, such as refs/for/main, had the same empty patch. Those pushes now keep the remote's commit as their base, as before this change: a push of a commit the tracking ref already holds, and a push to a ref outside refs/heads/. The tests push from a differently named local branch, so they fail if the hook reads the source ref where it needs the destination. Found by a third Proofline review of this change.
When the remote's commit was missing from the checkout and the stale tracking ref already held the pushed commit, the merge-base fallback was the pushed commit itself. The hook then compared the commit with itself, found nothing to review and let the push through even with onIncomplete=block. Before this change the missing commit surfaced as a failed diff. It now surfaces as "names no commit in this checkout", so the push prints as not reviewed and onIncomplete applies. Found by a fourth Proofline review of this change.
A push to the remote's default branch, or to a destination outside refs/heads/, is compared only with the commit the remote advertises. When that commit was missing from the checkout, the selector still fell back to the merge-base with the stale tracking ref and could review the wrong commits. Those pushes now print as not reviewed, as the missing commit did before this change, so onIncomplete applies. The rewind tests also push a further local commit, whose merge-base with the tracking ref differs from the pushed commit, so removing either destination check fails them. Found by a fifth Proofline review of this change.
The selector fell back to the remote's commit only when the merge-base with the tracking ref was the pushed commit itself. A different commit with the same files, such as an empty commit on the default branch's tip force-pushed over a branch, still produced an empty patch, so a push that removed the branch's changes found nothing to review. The fallback now applies whenever the merge-base has the pushed commit's tree. A missing refs/remotes/<remote>/HEAD is now read as no default branch before `git symbolic-ref` runs, whatever status it exits with for a missing ref. The refs/for/main cases push from a branch that is not the default, so passing the source ref where the destination belongs fails the tests. Found by a sixth Proofline review of this change.
This branch has not been deployed
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.
Summary
After a developer merges or rebases
maininto their branch, theproofline hooks install --pre-pushhook sent everyone else's newly mergedmaincode to review along with the push. This PR makes the hook review only what the branch adds, the same view its pull request shows, without ever turning a real change into an empty review.Walkthrough (2 min)
PR-walkthrough.mp4
Problem
For a branch the remote already has, the hook diffed the remote's old tip against the new local tip (
remote_sha..local_sha). After syncing withmain, that range contains every commit that landed onmainin the meantime, so the push review:mainonIncomplete=blockReproduced on
main(39b8065) with a realgit pushthrough the installed hook. Two branches were pushed, a teammate addedteammate.rstomain, then one branch mergedmainand the other rebased onto it:git merge origin/main, edit, pushfeature-a.rs,teammate.rsfeature-a.rsgit rebase origin/main, edit,push --forcefeature-b.rs,teammate.rsfeature-b.rsFix
git::pushed_branch_basepicks the base for each destination the remote already has. The hook now keeps the destination ref from Git's pre-push input (PushedRef::remote_ref).maincommits (merge or rebase): compare with its merge-base with<remote>/HEAD, like a pull request.<remote>/HEADnever produces "nothing to review". The remote's commit stays the base for pushes to the default branch itself, to refs outsiderefs/heads/(such asrefs/for/main), and whenever the merge-base has the same tree as the pushed commit. If that commit is missing locally, the push prints as not reviewed (… names no commit in this checkout), soonIncompleteapplies.Branches with no history in common with
main(such asgh-pages), or no<remote>/HEADat all, keep the old behaviour.Trade-off: after a merge or rebase, the review covers the whole branch, like a PR, rather than only the commits since the last push. Git can't express "only my new commits" as a single base once
mainis interleaved, and the alternative is re-reviewing other people's code.Changes:
src/git.rs,src/hooks.rs,tests/hooks.rs.Verification
tests/hooks.rs, the real binary against the existing stub console): five new tests cover merge, rebase, amend, a missing remote commit, a stale tracking ref after a rewind (to the default branch, another branch andrefs/for/main), a force-pushed empty commit, and orphan branches. Each failed before its fix.HEAD, or swapping the source and destination refs makes at least one test fail.mainand for this branch.cargo fmt --check,cargo clippy --locked --all-targets -- -D warnings,cargo test --locked,cargo deny checkand the script tests all pass.Reproduce by hand:
Proofline review
I ran Proofline on this change in my own org, utkarshlab-1/cli#1, across 8 pushes.
mainwith a staleorigin/mainfound "nothing to review" and passed underonIncomplete=block; the tests always pushedHEADrefs/for/*; the tests didn't separate source and destination refsUnknownRevisionrather than the suggestedNoBasebecause it names the real cause. Declined a "still present" on the parser test: breaking the parser makes it failrefs/for/maintests pushed frommainsymbolic-refexit-128 claim on git 2.43, but added the guard anywayAssessment: Proofline caught five real regressions my own tests missed, each of which could let a push through unreviewed or with the wrong base, and several tests that passed for the wrong reason. I reproduced every finding with a failing test, or by breaking the code on purpose, before changing anything. I declined two findings with evidence and stopped changing code after run 6, once the findings had narrowed to rare corner cases.
Known limitations
refs/for/*) still use the existingnew_branch_base, which this PR doesn't change.NoBasehint (git remote set-head) instead of naming the missing commit.<remote>/HEADthen doesn't describe the destination.