From 68c542c2ccb5a9ac6850ec79d84d201964f66710 Mon Sep 17 00:00:00 2001 From: "Merlin (they/them)" <421960+merlinpatt@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:33:47 -0500 Subject: [PATCH] Update pre-commit to run for certain files --- scripts/pre-commit | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index be6a4bd8..c8e37713 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -1,11 +1,19 @@ echo "***********************************************" echo "Running git pre-commit hook to lint and format." echo "***********************************************" -echo "" -# Gather the staged files - to make sure changes are saved only for these files. -stagedFiles=$(git diff --staged --name-only) +# The git diff and grep part is re-used to prevent a bug which leads to 0 files having a count of 1 +stagedFilesCount=$(git diff --staged --name-only | grep -E '(library|demo)' | wc -l | awk '{$1=$1};1') + +if [[ "$stagedFilesCount" -eq "0" ]]; then + echo "No staged demo/ or library/ files found when running git diff --staged | grep -E '(library|demo)'" + echo "***********************************************" + exit 0 +fi +echo "Found $stagedFilesCount staged files." +echo git diff --staged --name-only | grep -E '(library|demo)' +echo "" echo "Running ktFormat to fix any auto-fixable issues" ./gradlew ktFormat @@ -22,13 +30,17 @@ echo "" ./gradlew ktLint -error_count=$(grep "