fix(writer): reject commits with unchanged trees#379
Open
KSHITIZ6341 wants to merge 1 commit into
Open
Conversation
|
|
KSHITIZ6341
marked this pull request as ready for review
July 12, 2026 13:01
KSHITIZ6341
requested review from
floriecai and
konsalex
and removed request for
a team
July 12, 2026 13:01
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.
What
ErrNothingToCommitwhen staged operations rebuild the same root tree as the parent commit.Why
PackfileWriter.HasObjects()reports whether blob or tree objects were staged, not whether the resulting repository tree changed. Re-staging identical content therefore rebuilt the same root tree but still allowedCommit()to create an empty commit, which could then produce a no-op receive-pack request.Good catch by @jdstrand; the reproduction clearly isolated the distinction between staged packfile objects and an unchanged commit tree.
Fixes #378
How
After pending trees are built,
Commit()compares the rebuilt root tree hash with the parent commit's tree hash before creating a commit object. A match returns the existingErrNothingToCommiterror. Commits whose final tree differs from the parent continue through the existing path unchanged.The signer unit-test fixtures now use a distinct parent tree so they continue to represent a real changed-tree commit.
Remarks
Behavioral effect: callers now receive
ErrNothingToCommitfor semantically unchanged staged updates, including an identicalUpdateBlob, instead of receiving a new commit. There is no public API change and changed-tree commits are unaffected.Checks performed:
go test -race -parallel 6 --short -count=1across all packages exceptprotocol/signinggo test . -run '^TestStagedWriter_Commit_(UnchangedTree|SignerError|SignerInvoked)$' -count=1make lintmake lint-staticcheckgit diff --checkmake test-unitcould not complete locally because the host does not have thegpgandgpgsmexecutables required byprotocol/signing; all other packages passed with the race detector.make test-integrationcould not start its Gitea fixture because no local Docker provider is available, so 0 of 321 integration specs ran locally.Author Checklist