Repository navigation
golang: remove older releases' go_env dirs before installing - #228
Merged
Merged
Conversation
The first install of a golang hook after upgrading to 4.7.1 from 4.7.0 or older failed with `pattern ./...: directory go_env-default/pkg/mod/... outside main module or its selected dependencies`. 4.7.1 renamed the env to upstream's golangenv but left the old go_env-<version> and bare go_env dirs in each hook clone, and those releases never removed GOPATH/pkg, so a full module cache sat inside the clone. `go install ./...` runs in the clone and refuses any module there without a go.mod of its own. Seen on gitleaks (goutils@v1.1.1 predates modules) on the first commit after `brew upgrade`. Nothing has read those dirs since the rename and no upstream language uses the name, so the install now removes them first. The wipe test for the env's own leftovers could not fail (its junk module had a go.mod, which the pattern skips); without that go.mod it now fails when the wipe is removed.
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.
Why
The first install of a
language: golanghook after upgrading to 4.7.1 from 4.7.0 or older fails:4.7.1 renamed the golang env to upstream's
golangenv(#161) but left older releases'go_env-<version>and barego_envdirs in every hook clone. Those releases never removedGOPATH/pkg, so each clone kept a full module cache (418 MB per gitleaks clone on one machine; 20 such dirs, 8.6 GB in all).InstallEnvironmentrunsgo install ./...in the clone, the pattern walks into that cache, and Go refuses any module there without its owngo.mod(goutils@v1.1.1 predates modules). Hit on the first commit afterbrew upgrade; CI was unaffected only because its cache started cold.What changed
removeLegacyGoEnvsruns beforego install ./...and removes only directories named exactlygo_envorgo_env-*directly in the clone, throughfsutil.RemoveAllbecause the module cache is read-only. Othergolangenv-*versions, files with those names, and lookalikes such asgo_envoy/are untouched.TestGolangInstallRemovesLegacyEnvDirsreproduces it with a read-onlygo_env-default/pkg/mod/.../goutils@v1.1.1that has nogo.mod.TestInstallEnvironmentsWipesStatelessLeftoverEnvcould not fail: its junk module had ago.mod, which./...skips. Without it, the test now fails when the env wipe is removed.Parity
Matches upstream. Upstream never names an env
go_env(checked every 4.7.0ENVIRONMENT_DIR), so these dirs exist only because of this port's pre-4.7.1 naming. Removing them leaves the clone as upstream's would be, and a store shared with Python pre-commit loses nothing.Checklist
pre-commit installis set up, so the commit hook (which lints) ran (golangci-lint included; it catches a planted unused func on these files)t.TempDir(),GOPROXY=off)go_env*dir exists)Evidence
os.RemoveAllinstead offsutil.RemoveAll;go_envwithout the-;go_envcase;IsDircheck.go_env-default/pkg/modplanted:golangenv-*, andbin/gitleaks versionruns.go test -race:internal/hookandinternal/fsutilpass.internal/languagespasses, apart from intermittentdial tcp 127.0.0.1:N: can't assign requested addressin untouched httptest-based tests (TestGolangInstallDownloadsGo,TestRustInstallEnvironment). Those also fail on an untouched main checkout on the same loaded machine.