Created
December 14, 2022 17:22
-
-
Save danielgomezrico/b8c86054998739226e63ee2d3a637d4f to your computer and use it in GitHub Desktop.
Git - hook - pre-commit: for flutter/dart format each modified file ultra fast before each commit
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/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) | |
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