From f37c34471f54961142ff7468ae65df79ac362b56 Mon Sep 17 00:00:00 2001 From: Jason D'Amour Date: Mon, 18 May 2026 16:01:35 -0700 Subject: [PATCH 1/2] Filter out GIT_WORK_TREE from cloner environment variables 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=) not allowed without specifying GIT_DIR (or --git-dir=). Follows the same pattern as #3760 (GIT_DIR) and #3813 (GIT_INDEX_FILE). Co-Authored-By: Claude Sonnet 4.6 --- private/pkg/git/cloner.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/private/pkg/git/cloner.go b/private/pkg/git/cloner.go index 1217f5a7ab..eb230ea2e8 100644 --- a/private/pkg/git/cloner.go +++ b/private/pkg/git/cloner.go @@ -77,12 +77,13 @@ func (c *cloner) CloneToBucket( depthArg := strconv.Itoa(int(depth)) envContainer = app.NewEnvContainerWithOverrides(envContainer, map[string]string{ - // In the case where this is being run in an environment where GIT_DIR and GIT_INDEX_FILE - // are set, e.g. within a submodule, we want to treat this as a stand-alone, non-bare - // clone rather than interacting with an existing GIT_DIR and GIT_INDEX_FILE. - // So we filter out GIT_DIR and GIT_INDEX_FILE from our environment variables. + // In the case where this is being run in an environment where GIT_DIR, GIT_INDEX_FILE, + // or GIT_WORK_TREE are set, e.g. within a submodule or git worktree, we want to treat + // this as a stand-alone, non-bare clone rather than interacting with an existing git + // directory. So we filter out these variables from our environment. "GIT_DIR": "", "GIT_INDEX_FILE": "", + "GIT_WORK_TREE": "", }) baseDir, err := tmp.NewDir(ctx) From 9a132b7dc5240a4c78715e5dcf72217cf302f002 Mon Sep 17 00:00:00 2001 From: Jason D'Amour Date: Tue, 19 May 2026 14:35:05 -0700 Subject: [PATCH 2/2] Add GIT_WORK_TREE env override test for git cloner Covers the worktree scenario where GIT_WORK_TREE is set in the environment, matching the env override tests added in #4550. Co-authored-by: Cursor --- private/pkg/git/git_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/private/pkg/git/git_test.go b/private/pkg/git/git_test.go index 426c2af626..8ad5013038 100644 --- a/private/pkg/git/git_test.go +++ b/private/pkg/git/git_test.go @@ -370,6 +370,21 @@ func TestGitCloner(t *testing.T) { assert.Equal(t, "// commit 2", string(content)) }) + t.Run("env_override=GIT_WORK_TREE", func(t *testing.T) { + t.Parallel() + readBucket := readBucketForName(ctx, t, workDir, readBucketForNameOptions{ + envOverrides: map[string]string{ + // Simulates running inside a git worktree where GIT_WORK_TREE + // points at the worktree's working directory. + "GIT_WORK_TREE": workDir, + }, + }) + + content, err := storage.ReadPath(ctx, readBucket, "a.proto") + require.NoError(t, err) + assert.Equal(t, "// commit 2", string(content)) + }) + t.Run("env_override=GIT_DIR,GIT_INDEX_FILE", func(t *testing.T) { t.Parallel() tempDir := t.TempDir()