Open pcwalton opened 9 years ago
see "Defining a custom merge driver": https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver
To add to this, NPM/Yarn have already implemented this feature officially.
cc #5831
I really like this feature, and enjoy it a lot in yarn.
So there are actually two different solutions here, and I think we should follow npm's lead and implement both:
Here are some references:
From reading the documentation/PRs linked in this ticket, I get the following understanding (please correct at any stage if I am wrong):
.git/config
and .gitattributes
.Thoughts? If my understanding is correct, then I would start working on such a merge driver :)
It's unfortunate you only got reactions for this and not a real response, @thomaseizinger.
- Custom git merge drivers are automatically invoked as soon as the conflict occurs.
I can confirm this from experience. Here's an example from npm: https://github.com/npm/npm-merge-driver
Hence we could start implementing this as a totally separate binary without needing any support for it in cargo.
Sounds like standard practice in Rust-land.
If the custom merge driver is activated in a repository, cargo would practically never see a lock file with merge conflicts again, unless the driver fails to resolve the conflicts.
Right. Emphasis on "unless". I don't expect this to always be able to resolve them.
- Once the tool is mature enough, it could be included in cargo as a subcommand and cargo could automatically register the merge driver when it initializes a project.
That would be super sweet.
Thanks @mightyiam !
I have to admit, this was no longer on my radar at all. The latest lockfile version only rarely produces conflicts in my experience.
For Cargo.toml, I am not sure we can automatically resolve conflicts at all?
I haven't thought this through. I hope some smart people will!
The latest lockfile version only rarely produces conflicts in my experience.
In case anyone else wants context on this, https://github.com/rust-lang/cargo/pull/7070 changed the lockfile to make it produce fewer conflicts
Note that https://github.com/relrelb/cargo-merge-driver exists, which seems to work (though it could maybe do with some updating of e.g. the beta clap
version it's using).
Edit: updated deps and README at https://github.com/afranchuk/cargo-merge-driver
@afranchuk sadly, that's not a real merge driver, just a hack that always updates all packages to their latest versions. A real merger should parse all lock files, identify the changes and merge them roughly according to these rules:
Also FYI I made a merge tool to resolve use
statements. It's quite sketchy so far but does work in some cases. I've since learned about merge drivers and I think it'd be better suitable as a driver.
It's terribly annoying to have tons of Cargo.lock and Cargo.toml merge conflicts when rebasing pretty much any Rust PR on any large repo. It would be nice to have custom merge tools that automatically do the right thing here.