Created
January 20, 2023 16:32
-
-
Save danielgomezrico/6f88ceb468162385fc7075e73817ec67 to your computer and use it in GitHub Desktop.
Git - Hook - Pre Commit - Flutter: format files before they are commited
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 | |
# | |
# Autoformat all modified files before commit | |
# | |
function format_if_required { | |
FILES=$1 | |
flutter format $FILES | grep -Ev '^(Unchanged)' | |
echo "--> Autoformat was applied/checked ✅" | |
} | |
echo "----------------------------------------------------------" | |
echo " Checking code format on staged files" | |
echo "----------------------------------------------------------" | |
CHANGED_FILES=$(git diff --diff-filter=d --cached --name-only | grep .dart) | |
if [ -z "$CHANGED_FILES" ]; | |
then | |
echo "--> No files added to check" | |
else | |
format_if_required $CHANGED_FILES | |
fi | |
echo "--> Commit is ok ✅" | |
echo "----------------------------------------------------------" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment