Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Do not automatically update go.mod and go.sum files #2730

Closed
CameronGo opened this issue Sep 4, 2019 · 6 comments
Closed

Do not automatically update go.mod and go.sum files #2730

CameronGo opened this issue Sep 4, 2019 · 6 comments
Labels
go-modules Related to Go modules

Comments

@CameronGo
Copy link

When opening a Go project that is using modules the go.mod and go.sum files are updated immediately when the project is opened and when almost anything changes. This is problematic when making small hotfixes to the application where it is undesirable to update dependencies. In order to keep dependencies at current levels you must continually discard changes from SCM to ensure they are not checked in. Obviously excluding these files from SCM is not an option.

Steps to Reproduce:

  1. Open any Go project that is using Go modules
  2. Within a few seconds you will see the go.mod and go.sum files as modified with changes pending commits to SCM
@ramya-rao-a
Copy link
Contributor

Can you share any Go related settings you might have added/edited? You can see these by running the command Preferences: Open Settings (JSON)

@CameronGo On each file save, we run go build for your package in order to show build errors if any. I wonder if that is what is causing updates to the go.mod and go.sum files. The extension itself doesn't directly ever touches these files

@stamblerre Correct me if I am wrong, but doesn't go build have the potential to update the go.mod and go.sum files?

@stamblerre
Copy link
Contributor

Yes, the go command modifies your go.mod files. @CameronGo: You'll notice that your go.mod will change if you run go build from the command line too.

@CameronGo
Copy link
Author

@ramya-rao-a the only go related settings i have changed at this point are:

    "go.useLanguageServer": true,
    "go.buildOnSave": "off"

I can confirm that yes running go build or go list or even go doc does in fact touch and update the go.mod and go.sum files.

Is it necessary to run any of those things as soon as a project is opened or on file save? As it stands today our engineers are just constantly running git reset --hard as soon as a project is opened and when there are minor changes being made or when flipping back and forth between branches. It is a real hassle.

@ramya-rao-a
Copy link
Contributor

@CameronGo
If you have the language server enabled, then the extension does not run go build, but it might run go list to provide one of the various other features.

@stamblerre What would you suggest here?

@ramya-rao-a ramya-rao-a added the go-modules Related to Go modules label Sep 12, 2019
@stamblerre
Copy link
Contributor

gopls runs go list under the hood, and go list will potentially modify your go.mod file. There is nothing that VSCode or gopls can do here - this is a behavior of the Go command.

@CameronGo: I recommend taking a look at golang/go#27643 and the related issues.

@ramya-rao-a
Copy link
Contributor

Thanks @stamblerre

Closing this issue as unfortunately we cannot avoid running go list

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
go-modules Related to Go modules
Projects
None yet
Development

No branches or pull requests

3 participants