Skip to content

Instantly share code, notes, and snippets.

@Gnappuraz
Last active October 11, 2018 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gnappuraz/aa082122ba9ce1c76a4149404f8255ec to your computer and use it in GitHub Desktop.
Save Gnappuraz/aa082122ba9ce1c76a4149404f8255ec to your computer and use it in GitHub Desktop.
Git pre-commit hook to run clang-format and linters from bitcoin
#!/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