google / yapf

A formatter for Python files
Apache License 2.0
13.77k stars 891 forks source link

git like merge tool integration #133

Open Jbonnett opened 9 years ago

Jbonnett commented 9 years ago

Given that its early days still and not every change yapf makes is a winner, having a quick and standardized way to merge the changes you like and ignore the ones you don't, sounds like a win to me.

I am thinking of a feature that works like the git mergetool command. Thoughts?

eliben commented 9 years ago

Can you clarify what you mean?

Jbonnett commented 9 years ago

Sure thing. I think it would be great if you could run

yapf --pick-changes -t meld -r .

and have yapf go file by file, generating formatted files and putting them next to the originals with a .formatted suffix. Then it would call meld (or other visual diff tool) with the original and the formatted version of the file, allowing you to pick and choose the changes you like.

This directly imitates the git mergetool command, which you can use to resolve merge conflicts. Example. Of course, Git needs to do a 3 way merge, because of the aforementioned conflicts, but all of these tools also support simple 2 way merges.

You could diff everything yourself and clean up the spare files after, but this is just a small bit of code to increase ease of use.

(PS: I am not married to any particular naming scheme. --pick-changes probably isn't the right name for this feature.)