Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created December 14, 2022 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/b8c86054998739226e63ee2d3a637d4f to your computer and use it in GitHub Desktop.
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
#!/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