feat(buffetch): add merge_base option to buf breaking --against#4551
Open
jasondamour wants to merge 8 commits into
Open
feat(buffetch): add merge_base option to buf breaking --against#4551jasondamour wants to merge 8 commits into
jasondamour wants to merge 8 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds TestRefParserGitMergeBaseValidation covering the valid merge_base case (GitMergeBase, Depth defaulting to 50, nil GitName) and three invalid cases where merge_base is combined with branch, ref, or commit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Closes #4495
Summary
Adds a
merge_base=<ref>option to the--againstflag ofbuf breaking, so users can write:instead of the shell workaround:
This is especially useful in pre-commit hook tools (e.g. prek) that don't expose the merge-base commit as an environment variable.
How it works
When
merge_base=<ref>is specified:buffetchref-parsing pipeline and stored on theGitRefinterface asGitMergeBase() string.getGitBucket(), buf runsgit merge-base HEAD <ref>against the local repository to resolve the common ancestor commit hash.ref=<hash>), so the comparison is against the exact point where the current branch diverged from<ref>.merge_baseis only supported for local git references (e.g..git#merge_base=main). For remote repos, the existing shell workaroundref=$(git merge-base HEAD origin/main)remains the approach.Constraints
branch,commit,tag, orref(returns a clear error)depth=50(same asref=)Changes
private/pkg/git/git.goGetMergeBase()helperprivate/buf/buffetch/internal/errors.goprivate/buf/buffetch/internal/internal.goGitMergeBasetoRawRefandGitRefinterfaceprivate/buf/buffetch/internal/git_ref.gogitMergeBasefield and accessorprivate/buf/buffetch/internal/ref_parser.gomerge_basethroughprivate/buf/buffetch/internal/reader.goprivate/buf/buffetch/internal/ref_parser_test.goTest plan
ref_parser_test.gocovering valid parsing and all invalid combinationsbuf breaking . --against ".git#merge_base=main"produces identical output tobuf breaking . --against ".git#ref=$(git merge-base HEAD main)"buffetchandgitpackage tests pass🤖 Generated with Claude Code