Created
August 15, 2021 15:55
-
-
Save algermissen/a59b40d714dea0e2f0663c17150bd291 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/sh | |
# To use, store as .git/hooks/pre-commit inside your repository and make sure | |
# it has execute permissions. | |
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') | |
if [ ! -z "$gofiles" ]; then | |
unformatted=$(goimports -l $gofiles) | |
if [ ! -z "$unformatted" ] ; then | |
# Some files are not goimports'd. Print message and fail. | |
echo >&2 "Go files must be formatted with goimports. Please run:" | |
for fn in $unformatted; do | |
echo >&2 " goimports -w $PWD/$fn" | |
done | |
fi | |
fi | |
tffiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.tf$') | |
if [ ! -z "$tffiles" ]; then | |
unformatted=$(terraform fmt -check $tffiles) | |
if [ ! -z "$unformatted" ] ; then | |
# Some files are not terraform fmt'd. Print message and fail. | |
echo >&2 "Terraform files must be formatted with goimports. Please run:" | |
for fn in $unformatted; do | |
echo >&2 " terraform fmt -write=true $PWD/$fn" | |
done | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment