-
Notifications
You must be signed in to change notification settings - Fork 619
Extend formatter script to run on all staged files, merge add/strip action #941
Conversation
591be2a
to
a6c6384
Compare
There was a typo in the commit message and in the title - of course it is meant to run on all staged files, not the other way round. |
* add -f option that applies the selected action to all staged files (git) * adapt pre-commit hook to only check stages files
a6c6384
to
770c42d
Compare
Perhaps a lame question, but how exactly do I test this? I'm on a Mac. |
Thanks! |
I installed the hook and edited few source files (made some of the lines longer that 80 chars), staged them and committed some of them, but the hook didn't stop me. Rather, I got this commit output:
EDIT: Turns out there was a problem with my local version of And, is there a way to only run the hook if there are staged files? I tried to commit without staging and the hook still ran. |
Tanks for testing!
The commit hook only checks staged files. But there is no way to temporary disable it, if that's what you mean. |
@tcm-marcel Maybe the formatter can be edited to only run when there are nonzero files passed to the |
* --update-header now updates or adds the header
@schedutron was right, I changed the hook to only run if actually .cpp/.h files are staged. If committing a non-source file, the validator would run with empty parameters otherwise. Referring to last team meeting I also merged the add/strip actions to a new update action, that updates the header or adds a new one if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a quick look at this. Looks good!
Also, since you're in this part anyways, can you add a pre-check in source_validator.py
that looks for clang-format
. It doesn't have to be 3.6, but it should print a nice error message, rather than a stack trace it currently does.
script/git-hooks/pre-commit
Outdated
python script/validators/source_validator.py --files $files | ||
exit $? | ||
files=$(git diff --name-only HEAD --cached --diff-filter=d | grep '\.\(cpp\|h\)$') | ||
echo $files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this echo
since all scanned files are printed in the source_validator.py
script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, the echo
is left from debugging and the exit $?
should of course stay there
@pmenon So you're suggesting that @tcm-marcel should add a |
* also add useful message if pre-commit hook fails
c99d138
to
b3011b0
Compare
* use any clang-format version * catch error if clang-format is not installed (similar to source validator changed in cmu-db#941) * fix wrong path in pre-commit hook fail message
* use any clang-format version * catch error if clang-format is not installed (similar to source validator changed in #941) * fix wrong path in pre-commit hook fail message
* use any clang-format version * catch error if clang-format is not installed (similar to source validator changed in cmu-db#941) * fix wrong path in pre-commit hook fail message
This is especially useful when using the new pre-commit hook that prevents me from committing.
(since -a, -s and -c were already taken, I just picked any other letter that somehow looks like "staged files" when looking from far away)
Testing: I run Ubuntu, can someone test this on a Mac?