Skip to content

Add git_diff behavior #118

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

Merged
merged 1 commit into from
Nov 25, 2021
Merged

Add git_diff behavior #118

merged 1 commit into from
Nov 25, 2021

Conversation

jreybert
Copy link
Contributor

Hello,

I am deploying the use of clang format in my team, and I am doing some experiments to use this tool, especially in editors.

Your addon is really great, but format the whole file could easily lead to unrelated diffs in some commits. Your option InsertLeave is actually ingenous, but depending on user movement it still could lead to large part of file reformating.

An easy way would be to integrate or mimic the tool clang-format-diff, and only format git diff chunks in the edited file.

This PR is still a work in progress, especially around the git integration and the possible options (for example, what to do in case of untracked file, fallback to whole file format or not). And no tests have been wrtten for the moment.
But I think it fits right in your system.

What do you think about this feature?

@jreybert
Copy link
Contributor Author

jreybert commented Nov 9, 2021

Cleanup the WIP, with clean code, extended documentation and descriptive commit.
If interested in the PR, I will write a test for this new behavior.

@jreybert jreybert force-pushed the git_diff branch 3 times, most recently from 7144b53 to fdcbd03 Compare November 10, 2021 01:16
@jreybert jreybert changed the title [WIP] add git_diff option Add git_diff behavior Nov 10, 2021
@jreybert jreybert force-pushed the git_diff branch 3 times, most recently from 16291ae to e591d20 Compare November 15, 2021 23:54
@jreybert
Copy link
Contributor Author

Hi @rhysd ,

thanks for your complete report. I think I addressed all of your comments. Do you have other concerns about this PR?

@jreybert jreybert requested a review from rhysd November 15, 2021 23:55
@jreybert
Copy link
Contributor Author

Thanks for all your comments, my vimscript is actually a bit rusty.

I think I answered all your comments, feel free if you have any other requirements.

Copy link
Owner

@rhysd rhysd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you for several updates.

@rhysd
Copy link
Owner

rhysd commented Nov 25, 2021

@jreybert Would you like to squash dd741ed?

When you edit a file tracked in git, it may happend that some tracked
lines are not well formatted. If you modify this file, and you
auto_format the file, lines with bad indentation will be formatted too.
You will be end up with unrelated changes in your commit.

It may even appear that these 'bad formatted lines' were indented like
this with a purpose.

To mitigate this issue, this commit proposes to only format diff'ed
lines in a file. It roughly relies on git diff, and on clang-format
'-lines' option.

clang_format#format function has been modified to accept a list of
ranges.

It adds three new user options:
- g:clang_format#auto_format_git_diff to enable this new behavior
- g:clang_format#auto_format_git_diff_fallback to decide what to do in
  case of untracked file
- g:clang_format#git to define non standard git path or options
@rhysd rhysd merged commit 17634d6 into rhysd:master Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants