clang-format-action icon indicating copy to clipboard operation
clang-format-action copied to clipboard

Allow applying corrections in place

Open patrickelectric opened this issue 2 years ago • 4 comments

This is helpful to show what would be necessary to change on the code to match the style

patrickelectric avatar Mar 14 '23 16:03 patrickelectric

applying corrections in place

By this, do you mean that you're requesting that this action pushes a commit that formats the files failing the check? If so, I won't be implementing that - my intent for this action is to provide a minimal-permission checker utility, not a fixer utility.

jidicula avatar Mar 18 '23 18:03 jidicula

I'm talking about running clang-format with -i or an option that would just show the necessary changes

patrickelectric avatar Mar 18 '23 20:03 patrickelectric

So I guess the procedure here would be

  1. Run clang-format -i
  2. Output a diff of all files that have changed by this. Easiest approach might be a git commit -am "Dummy" and then git diff HEAD~1

Krzmbrzl avatar Sep 10 '23 16:09 Krzmbrzl

So I guess the procedure here would be

  1. Run clang-format -i
  2. Output a diff of all files that have changed by this. Easiest approach might be a git commit -am "Dummy" and then git diff HEAD~1

This will not work I believe when the code is already formatted, because git commit -am "..." will not create a commit with empty diff. So the next cmd git diff HEAD~1 will not show the formatter diff, and instead show the previous normal commit diff.

Removing an extra step of creating a commit might work though:

git clang-format --diff -q origin/main

If the code is already formatted, the cmd returns an empty string, otherwise it will show the desired diff.

678098 avatar Mar 14 '24 13:03 678098