diff --git a/hooks/pre-commit b/hooks/pre-commit index 95066ae..e06ef62 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,4 +1,12 @@ -git_dir=$(git rev-parse --git-dir) -project_dir=$(dirname $git_dir) +#!/bin/sh +# adapted from https://prettier.io/docs/en/precommit.html#option-5-shell-script +FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | grep '.dart$') +[ -z "$FILES" ] && exit 0 -dart format $project_dir +# Format all selected files +echo "$FILES" | xargs dart format + +# Add back the formatted files to staging +echo "$FILES" | xargs git add + +exit 0