I am using pre-commit (version 2.20.0) for my C++ project with this hook:
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
I just staged a few lines each from a few different .cpp/.h/cmakelists files. When I try to commit those changes, I get the following error from pre-commit:
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\tyler.shellberg\.cache\pre-commit\patch1665600217-21836.
clang-format.............................................................Failed
- hook id: clang-format
- files were modified by this hook
[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
[INFO] Restored changes from C:\Users\tyler.shellberg\.cache\pre-commit\patch1665600217-21836.
I am confused by this. Does pre-commit not allow me to partially commit files, or to have unstaged changes at all when committing?
All the files, both staged and un-staged, have been formatted by clang-format. I've manually double-checked this.
Edit for clarity:
If I run pre-commit run --files [filename] on each file (staged and unstaged) all report back either "Passed" or "Skipped" (for the non-cpp files). If all files pass, why is there a problem?
the first part of your output is:
[WARNING] Unstaged files detected.
this means you had a partially staged commit -- this is fine, pre-commit supports this well
then after that a hook made changes:
- files were modified by this hook
these changes must've conflicted with the unstaged parts because then there's a message such as:
[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
meaning you'll need to either make sure the unstaged parts are formatted properly (pre-commit run --files whatever.cpp) or stage those as well so they also get formatted
disclaimer: I created pre-commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With