Skip to content

cmd/go: report an added go directive as added, not downgraded#80034

Open
harjothkhara wants to merge 1 commit into
golang:masterfrom
harjothkhara:fix/cmd-go-added-go-directive-msg-63507
Open

cmd/go: report an added go directive as added, not downgraded#80034
harjothkhara wants to merge 1 commit into
golang:masterfrom
harjothkhara:fix/cmd-go-added-go-directive-msg-63507

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

When 'go get go@version' runs in a module whose go.mod has no go
directive, the go command synthesizes the current version into the
in-memory requirements before writing the file. reportChanges then
compared the requested version against that synthesized version and
printed a misleading message, for example:

go: downgraded go 1.27 => 1.20

even though the module never declared go 1.27. Report the change as the
directive being added instead:

go: added go 1.20

Determine whether the go.mod originally declared a go directive from the
main module's index, which is not affected by the synthesized directive,
and treat an absent directive as having no previous version. Existing go
directives are still reported as upgrades or downgrades, and changes that
only write back the synthesized version stay silent.

This affects 'go get' in module mode with a single main module. In
workspace mode the change report is still suppressed for an added go
directive, but that is a separate, pre-existing issue (the workspace
load synthesizes the directive into the in-memory go.mod before the
change is computed) and is out of scope here.

Fixes #63507
Fixes #70090

@JoesSon72

Copy link
Copy Markdown

Thanks Jesus Loves you #SayerTurner

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: f038d5b) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/791300.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@harjothkhara harjothkhara force-pushed the fix/cmd-go-added-go-directive-msg-63507 branch from f038d5b to bf61540 Compare June 16, 2026 19:12
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: bf61540) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/791300.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@harjothkhara harjothkhara marked this pull request as ready for review June 16, 2026 19:15
@harjothkhara harjothkhara force-pushed the fix/cmd-go-added-go-directive-msg-63507 branch from bf61540 to fff69f6 Compare June 16, 2026 19:38
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: fff69f6) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/791300.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Harjoth Khara:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791300.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Dmitri Shuralyov:

Patch Set 3: Code-Review+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791300.
After addressing review feedback, remember to publish your drafts!

When 'go get go@version' runs in a module whose go.mod has no go
directive, the go command synthesizes the current version into the
in-memory requirements before writing the file. reportChanges then
compared the requested version against that synthesized version and
printed a misleading message, for example:

	go: downgraded go 1.27 => 1.20

even though the module never declared go 1.27. Report the change as the
directive being added instead:

	go: added go 1.20

Determine whether the go.mod originally declared a go directive from the
main module's index, which is not affected by the synthesized directive,
and treat an absent directive as having no previous version. Existing go
directives are still reported as upgrades or downgrades, and changes that
only write back the synthesized version stay silent.

This affects 'go get' in module mode with a single main module. In
workspace mode the change report is still suppressed for an added go
directive, but that is a separate, pre-existing issue (the workspace
load synthesizes the directive into the in-memory go.mod before the
change is computed) and is out of scope here.

Fixes golang#63507
@harjothkhara harjothkhara force-pushed the fix/cmd-go-added-go-directive-msg-63507 branch from fff69f6 to a451b8e Compare June 20, 2026 02:49
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: a451b8e) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/791300.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Harjoth Khara:

Patch Set 4:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791300.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Harjoth Khara:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791300.
After addressing review feedback, remember to publish your drafts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants