Skip to content

cmd/go: never remove the toolchain directive when tidying #75331

@maxbrunet

Description

@maxbrunet

When the go and toolchain directives are equal, go mod tidy removes the toolchain directive, which in my opinion, "removes the intent" of managing the toolchain version with the go.mod file.

When that happens, tools like dependency update automation (e.g. Dependabot, Renovate) will stop updating the Go version of the project (since the go directive is the minimal supported version, it is not usually desirable to update with the same frequency). And these tools will not add it back since they cannot tell whatever the user wishes to use toolchain, the "intent" has been removed.

The go directive often gets bump by go mod tidy when a dependency requires it, which happens fairly often.

The current behavior adds extra work for the user to keep an eye on the presence of the toolchain directive in their go.mod file, to add it back when there is a new release. Possibly allowing CVEs to accumulate if they do not notice or forget.

Basically, when a user has opted into using toolchain, they should never be opted out by go mod tidy.

Would that sound like reasonable change for go mod tidy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions