Filter out GIT_WORK_TREE from cloner environment variables#4549
Open
jasondamour wants to merge 3 commits into
Open
Filter out GIT_WORK_TREE from cloner environment variables#4549jasondamour wants to merge 3 commits into
jasondamour wants to merge 3 commits into
Conversation
When buf breaking --against is run inside a git worktree, the GIT_WORK_TREE environment variable is set by the shell. Passing it to the cloner's git init/fetch/checkout sequence causes git to error: fatal: GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>). Follows the same pattern as bufbuild#3760 (GIT_DIR) and bufbuild#3813 (GIT_INDEX_FILE). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Member
|
This generally looks good -- any chance you could merge |
Covers the worktree scenario where GIT_WORK_TREE is set in the environment, matching the env override tests added in bufbuild#4550. Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
@doriable done! |
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
Follows the same pattern as #3760 (
GIT_DIR) and #3813 (GIT_INDEX_FILE) to fix the same class of issue (#3752) for git worktrees.When
buf breaking --againstis run inside a git worktree (e.g. via a pre-commit hook in a Cursor/VS Code worktree), the shell setsGIT_WORK_TREEpointing at the worktree's working directory. Passing this variable into the cloner'sgit init/git fetch/git checkoutsequence causes git to reject the operation:The fix is a one-liner: add
"GIT_WORK_TREE": ""to the existing env-sanitization map inprivate/pkg/git/cloner.go, so the cloner always starts with a clean git environment regardless of how buf was invoked.Test plan
buf breaking --againstfrom inside a git worktree (e.g..cursor/worktrees/...) and confirm noGIT_WORK_TREEerrorgo test ./private/pkg/git/...)🤖 Generated with Claude Code