Skip to content

feat: add prune command to remove superseded versions - #189

Merged
voidint merged 1 commit into
voidint:masterfrom
tr1v3r:feat/prune
Aug 30, 2026
Merged

feat: add prune command to remove superseded versions#189
voidint merged 1 commit into
voidint:masterfrom
tr1v3r:feat/prune

Conversation

@tr1v3r

@tr1v3r tr1v3r commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Motivation

Each installed Go version takes up a few hundred megabytes. Upgrading within a minor series (e.g. g install 1.24 resolving to the latest 1.24.x) leaves the older patch versions installed, and today they can only be reclaimed by calling g uninstall once per version.

This adds a g prune command that removes superseded versions automatically.

Behavior

  • Groups installed versions by major.minor series and keeps only the newest version of each series (e.g. with 1.19.10, 1.19.13, 1.20.5, 1.24.5, 1.24.6 installed, 1.19.10 and 1.24.5 are removed).
  • Never removes the version currently in use, even if it is not the newest in its series. (This protection is also missing from g uninstall today — worth a follow-up, but kept out of this PR to stay minimal.)
  • Prereleases are superseded by the final release of the same series (1.25rc1 is pruned once 1.25.0 is installed).
  • --dry-run prints what would be removed without deleting anything.
  • Idempotent: a second run reports Nothing to remove.
$ g ls
  1.19.10
  1.19.13
  1.20.4
* 1.24.3
  1.24.6
$ g prune --dry-run
Would remove 1.19.10
$ g prune
Removed 1.19.10

Implementation

  • cli/prune.go: thin action over listLocalVersions + a pure superseded() helper (versions are sorted ascending, so a version is superseded when its successor belongs to the same minor series).
  • version/version.go: adds Major()/Minor() accessors for series grouping.
  • cli/commands.go: registers the prune command.
  • Bilingual README updates (README.md, README_CN.md).
  • cli/prune_test.go: table-driven tests covering grouping, in-use protection, prerelease ordering, and major-series independence.

Testing

  • go build ./..., go vet ./cli/ ./version/, gofmt clean.
  • go test ./cli/ ./version/ pass.
  • Packages collector, pkg/http, pkg/sdk/github currently fail in my environment on both this branch and pristine master (they hit real network URLs behind a corporate proxy), so they are unrelated to this change.
  • Manual smoke test against an isolated G_HOME (create version dirs, symlink go to an older patch, run g prune / g prune --dry-run / g ls).

@tr1v3r
tr1v3r marked this pull request as ready for review August 26, 2026 07:44
Each Go installation takes up a few hundred megabytes, and upgrading
within a minor series (e.g. `g install 1.24` picking up the latest
patch) leaves the older patch versions behind until they are uninstalled
one by one.

`g prune` removes versions superseded within their minor series,
keeping the newest version of each series. The version currently in
use is never removed. `--dry-run` previews what would be removed.
@voidint
voidint merged commit 02dade9 into voidint:master Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants