Created
May 24, 2020 19:18
-
-
Save miawgogo/19fe2aa318ff5fda8968bf19190b7e68 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
mapfile -t files < <(git diff --name-only | grep "^.*\.(c|h|cpp|hpp|m|mm)$" -E) | |
dirtyfiles=() | |
pathtop=$(git rev-parse --show-toplevel) | |
for i in "${files[@]}" | |
do | |
clang-format --dry-run -Werror $1 "$pathtop/$i" &>/dev/null | |
if [[ $? != 0 ]]; then | |
dirtyfiles+=( "$i" ) | |
fi | |
done | |
set +x | |
if [[ ${#dirtyfiles[@]} != 0 ]]; then | |
echo "=================================" | |
echo "Files were not formatted properly" | |
for i in "${files[@]}"; do echo $i; done | |
echo "=================================" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment