git-cmake-format icon indicating copy to clipboard operation
git-cmake-format copied to clipboard

Don't unstage on failure

Open saferoll opened this issue 7 years ago • 5 comments

Why git reset all files when the check fails? This is REALLY annoying.

saferoll avatar Nov 17 '17 20:11 saferoll

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.

kbenzie avatar Nov 17 '17 22:11 kbenzie

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.

kbenzie avatar Nov 17 '17 22:11 kbenzie

But why call this?: subprocess.Popen([Git, "reset", "HEAD", "--", "."])

saferoll avatar Nov 17 '17 23:11 saferoll

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.

kbenzie avatar Nov 19 '17 13:11 kbenzie

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.

upsj avatar Dec 03 '19 13:12 upsj