From b013964615cc8206f27ad64e7e4a3cc140b29335 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 22 Feb 2024 15:32:55 +0100 Subject: [PATCH] Fixed hooks --- hooks/pre-commit | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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