git-cmake-format
git-cmake-format copied to clipboard
Don't unstage on failure
Why git reset all files when the check fails? This is REALLY annoying.
Its been a long time since I've looked at this if I'm honest but I think it was possible to commit the patch even though the hook rejected it. If this is not the case then I'm happy to accept a PR removing this but please do ensure that hook isn't being circumvented. Apologies for the annoyance @saferoll.
Actually I've just remembered why! clang-format
is being run on the files on disk not the staged changes, so once the files on disk are formatted correctly the hook will not fail even though the patch contains badly unformatted code which is the opposite of what is desired.
But why call this?: subprocess.Popen([Git, "reset", "HEAD", "--", "."])
As I said before, the staged changes contain badly formatted code but after running clang-format the hook will not fail, this relies on the user to stage the newly formatted code but if this is not done then badly formatted code could be committed. I will admit this is a heavy handed approach and am open to suggestions for better solutions.
Actually I've just remembered why!
clang-format
is being run on the files on disk not the staged changes, so once the files on disk are formatted correctly the hook will not fail even though the patch contains badly unformatted code which is the opposite of what is desired.
In case you want to resolve this issue: clang-format
is actually being executed on the output of git show
, i.e., the staged changes only (see L58)
The git reset
call can thus be safely removed, as no files are changed by clang-format
.