Skip to content

Instantly share code, notes, and snippets.

@rflpazini
Last active January 23, 2019 13:40
Show Gist options
  • Save rflpazini/ccebe0708d853371b8cc9153b0a7f92e to your computer and use it in GitHub Desktop.
Save rflpazini/ccebe0708d853371b8cc9153b0a7f92e to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
BASE_NAME=$(basename `git rev-parse --show-toplevel`)
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
GREEN="\033[1;32m"
NOCOLOR="\033[0m"
echo "\nRunning pre-commit checks on $BASE_NAME..."
FILES=$((git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.java$") || true)
[ -z "$FILES" ] && exit 0
echo "* ๐Ÿ™‰ Our monkeys started to doing the hard work"
COMMA_FILES=$(echo "$FILES" | paste -s -d "," -)
"${REPO_ROOT_DIR}/gradlew" goJF -DgoogleJavaFormat.include="$COMMA_FILES" &>/dev/null
git add $(echo "$FILES" | paste -s -d " " -)
read -a arr <<< $FILES
for i in "${arr[@]}"
do
echo "${GREEN} \xE2\x9C\x94${NOCOLOR} $i"
done
echo "* ๐ŸŽ‰ Everything is fine now \n "
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment