Repository navigation
Conversation
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.
Problem
In
src/hooks.rs,Hook::PrePushpreviously usedpushed.remote_shaunconditionally as the diff base whenever it was non-zero.When a developer force-pushes after rebasing onto an updated target branch (or amending a commit),
remote_shais no longer an ancestor oflocal_sha:git diff <remote_sha> <local_sha>diffs the stale pre-rebase tip against the rebased tip, uploading unrelated commits that landed on the target branch (or hitting patch size/file limits).remote_shais absent from the local object store (e.g., shallow clone or an un-fetched remote tip overwritten elsewhere),git difffails and the push is reported asUnreviewed.Solution
git::is_ancestor(dir, ancestor, descendant)insrc/git.rsusinggit merge-base --is-ancestor, returningOk(true)on exit0,Ok(false)on exit1(not an ancestor) or on exit128only whendescendantresolves andancestoris missing locally (GitError::UnknownRevision), andErr(GitError::Failed | GitError::NotSha | GitError::Unavailable)otherwise.hooks::subjectsinsrc/hooks.rsso non-zeroremote_shavalues are only used as the diff base whengit::is_ancestor(here, &pushed.remote_sha, &pushed.local_sha)returnsOk(true). OnOk(false), it falls back togit::new_branch_base(here, remote, &pushed.local_sha)(the merge-base withrefs/remotes/<remote>/HEAD), matching new-branch behavior and keeping fast-forward pushes unchanged.Verification
git::tests::is_ancestor_distinguishes_linear_diverged_and_missing_commitsinsrc/git.rs.force_push_of_rebased_or_missing_remote_tip_falls_back_to_default_branch_baseintests/hooks.rs.cargo fmt --check— passed.cargo clippy --locked --all-targets -- -D warnings— passed.cargo test --locked --lib git::tests— 5 passed, 0 failed.cargo test --locked --test hooks— 5 passed, 0 failed, 1 ignored (the_pre_commit_framework_preserves_selection_policy_and_existing_configuration, requirespre-commit >= 3.2.0).