Last active
October 11, 2018 14:06
-
-
Save Gnappuraz/aa082122ba9ce1c76a4149404f8255ec to your computer and use it in GitHub Desktop.
Git pre-commit hook to run clang-format and linters from bitcoin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
script_dir="contrib/devtools" | |
files_to_commit=$(git diff-index --cached --name-only --diff-filter=d HEAD) | |
format_paths="src/esperanza src/snapshot" | |
for file in ${files_to_commit} | |
do | |
for path in $format_paths | |
do | |
if [[ "${file}" =~ $path ]] ;then | |
echo $path | |
clang-format -i ${file} -style=file && git add ${file} | |
fi | |
done | |
done | |
# check for empty commits after reformat and prevent them | |
files_to_commit=$(git diff-index --cached --name-only --diff-filter=d HEAD) | |
if [ -z ${files_to_commit} ] ;then | |
echo "Nothing to commit after reformat!" | |
exit 1 | |
fi | |
# run lint checkers | |
lint_command="${script_dir}/check-doc.py && \ | |
${script_dir}/check-rpc-mappings.py . && \ | |
${script_dir}/lint-all.sh" | |
eval ${lint_command} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment