Skip to content

Commit 547784a

Browse files
jlecclaude
andauthored
fix(exec): deduplicate GOPATH before prepending version-specific path (#553)
When goenv exec is called from inside a shell that already has GOPATH set by goenv (e.g. a tool like gup that shells out to `go env GOPATH` through the goenv shim), exec.go was blindly prepending the version-specific path without filtering existing goenv-managed entries. This produced a doubled GOPATH such as: /Users/user/go/1.26.3:/Users/user/go/1.26.3 Which caused gup to construct the literal path `/Users/user/go/1.26.3:/Users/user/go/1.26.3/bin` and fail with "no such file or directory" when scanning for installed binaries. Apply the same deduplication guard already present in sh-rehash.go: filter out any $HOME/go/{version} entries from the existing GOPATH before appending, so re-entrant exec calls stay idempotent. Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1330a4b commit 547784a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

cmd/shims/exec.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,20 @@ func runExec(cmd *cobra.Command, args []string) error {
125125
// This allows users to keep source code in existing locations while
126126
// giving priority to version-specific installed tools/packages.
127127
// See: https://github.com/go-nv/goenv/issues/147
128+
// Filter out goenv-managed paths to prevent duplication when goenv exec
129+
// is called from inside an already-managed shell (e.g. a tool that
130+
// shells out to `go env GOPATH` through the shim).
128131
if gopath != "" {
129-
versionGopath = versionGopath + string(os.PathListSeparator) + gopath
132+
goPathPattern := filepath.Join(homeDir, "go")
133+
var filteredPaths []string
134+
for _, p := range filepath.SplitList(gopath) {
135+
if !strings.HasPrefix(p, goPathPattern+string(filepath.Separator)) || p == goPathPattern {
136+
filteredPaths = append(filteredPaths, p)
137+
}
138+
}
139+
if len(filteredPaths) > 0 {
140+
versionGopath = versionGopath + string(os.PathListSeparator) + strings.Join(filteredPaths, string(os.PathListSeparator))
141+
}
130142
}
131143

132144
execEnv = setEnvVar(execEnv, utils.EnvVarGopath, versionGopath)

0 commit comments

Comments
 (0)