Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: mitigate merge conflicts when modules are updated #32485

Open
vcabbage opened this issue Jun 7, 2019 · 6 comments
Open

cmd/go: mitigate merge conflicts when modules are updated #32485

vcabbage opened this issue Jun 7, 2019 · 6 comments
Labels
FeatureRequest GoCommand modules NeedsInvestigation
Milestone

Comments

@vcabbage
Copy link
Member

@vcabbage vcabbage commented Jun 7, 2019

I expect merge conflicts in go.mod and go.sum to be a relatively common occurrence.

Quoting from @bcmills in the Go Slack:

If you have a merge conflict no go.mod or go.sum, you can usually just remove the conflict markers (taking the union of the requirements) and then run go mod tidyto get back into a consistent state.

https://gophers.slack.com/archives/C9BMAAFFB/p1559923453042900?thread_ts=1559922004.041700&cid=C9BMAAFFB

This doesn't appear terribly burdensome but it does introduce friction in the development process. I'm opening this as an exploratory issue to investigate whether there's anything the tooling can/should do to mitigate the conflict.

My off the cuff question was whether go mod tidy could be updated to understand conflicts and automatically resolve them in go.mod and go.sum. My summary of the resulting conversation is that it's likely possible but it's unclear whether it's desirable.

Some of the reasons against that were brought up:

  • Both parsing of the conflicts and resolving them is VCS specific.
  • This may be expanding the scope of what tidy is responsible for farther than it should be.

It's possible there's a less invasive approach to mitigating conflicts so I'm including the above suggestion only as one potential option to explore.

@dmitshur dmitshur added NeedsInvestigation GoCommand labels Jun 7, 2019
@dmitshur dmitshur added this to the Go1.14 milestone Jun 7, 2019
@bcmills bcmills added the modules label Jun 7, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Jun 7, 2019

CC @jayconrod

@WIZARDISHUNGRY
Copy link

@WIZARDISHUNGRY WIZARDISHUNGRY commented Sep 5, 2019

I'd be interested in writing git specific merge driver for go.sum, if anyone else is thinking of the same thing.

@bcmills
Copy link
Member

@bcmills bcmills commented Sep 5, 2019

Thinking about this some more... if the area under the merge tokens contains a replace, require, or exclude token, then it isn't correct to just combine the contents. So the merge tool will at least need to know when to call for human intervention.

@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
@rbUUbr
Copy link
Contributor

@rbUUbr rbUUbr commented Jan 16, 2020

what about just deleting go.sum and running go mod download?

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 19, 2020

@rbUUbr, the point of the go.sum file is to ensure that the checksums do not change once a given version is downloaded. Especially for private dependencies that are not present in the global checksum database, it is important not to discard the originally-recorded checksums.

@yobert
Copy link

@yobert yobert commented Jul 18, 2021

It seems to me like the algorithm should be:
go.sum: Always merge contents together, deduplicating exact row matches
go.mod: Whenever conflicting part does not include replace/require/exclude, use MVS algorithm to resolve to the oldest version that satisfies both (in effect, choose the newest version). Any other conflicts, leave be for manual intervention.

Also I think a nice interface would be something like "go mod git-merge" or something like that. It could return an error exit code when it wasn't able to safely auto-merge everything. I think this could be plugged into .git/config so that doing a huge rebase with hundreds of commits would be mostly automatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest GoCommand modules NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

7 participants