[neomutt-devel] clang-format pre-commit hook
Julian Andres Klode
jak at jak-linux.org
Sat Jun 3 18:23:32 CEST 2017
Hi everyone,
I created a simple pre-commit hook to automatically run
clang-format on all changed files and prevent a commit
if there is a formatting error. This is quite useful.
==== START OF SCRIPT
result=0
for file in `git diff-index --cached --name-only HEAD` ; do
clang-format ${file} > ${GIT_DIR}/current_file
colordiff --label "$file (to be committed)" --label "$file (reformatted)" -u ${file} ${GIT_DIR}/current_file || result=1
done
rm ${GIT_DIR}/current_file
exit $result
==== END OF SCRIPT
I usually take the pre-commit.sample, rename that to pre-commit
change "exec git diff-index --check --cached $against --" to
"git diff-index --check --cached $against -- || exit 1" and then
append the stuff above.
Maybe it's useful for somebody else too.
--
Debian Developer - deb.li/jak | jak-linux.org - free software dev
| Ubuntu Core Developer |
When replying, only quote what is necessary, and write each reply
directly below the part(s) it pertains to ('inline'). Thank you.
More information about the neomutt-devel
mailing list