Created
June 28, 2022 15:35
-
-
Save BruceChen7/e4c0acadd988e910bb3d00519e77f2a1 to your computer and use it in GitHub Desktop.
#git#shell#go#gofmt
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/bash | |
errors=0 | |
for file in $(git diff --cached --name-only | grep "\.go"); do | |
diff="$(gofmt -d "${file}")" | |
if [[ -n "$diff" ]]; then | |
echo "# *** ERROR: *** File ${file} has not been gofmt'd." >> $1 | |
errors=1 | |
fi | |
done | |
if [[ $errors == "1" ]]; then | |
echo "# To fix these errors, run gofmt -w <file>." >> $1 | |
echo "# If you want to commit in spite of these format errors," >> $1 | |
echo "# then delete this line. Otherwise, your commit will be" >> $1 | |
echo "# aborted." >> $1 | |
fi |
Author
BruceChen7
commented
Aug 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment