From 07eb1fa382932298c068caeb5e87fb2c89c1a07f Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sun, 3 Dec 2023 11:32:45 -0700 Subject: [PATCH] Add pre-commit guard on empty state. --- specs/clang/template/.githooks/pre-commit | 7 ++++--- specs/mix/template/.githooks/pre-commit | 7 ++++--- specs/nodejs/template/.githooks/pre-commit | 7 ++++--- specs/phoenix/template/.githooks/pre-commit | 14 +++++++++----- specs/poetry/template/.githooks/pre-commit | 7 ++++--- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/specs/clang/template/.githooks/pre-commit b/specs/clang/template/.githooks/pre-commit index 8de71f8..4deba40 100755 --- a/specs/clang/template/.githooks/pre-commit +++ b/specs/clang/template/.githooks/pre-commit @@ -6,6 +6,7 @@ FORMAT_FILES=$( awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}' ) -clang-format -i "$FORMAT_FILES" - -git add "$FORMAT_FILES" +if [ -n "$FORMAT_FILES" ]; then + clang-format -i "$FORMAT_FILES" + git add "$FORMAT_FILES" +fi diff --git a/specs/mix/template/.githooks/pre-commit b/specs/mix/template/.githooks/pre-commit index 12eaaac..f15fd68 100755 --- a/specs/mix/template/.githooks/pre-commit +++ b/specs/mix/template/.githooks/pre-commit @@ -6,6 +6,7 @@ FORMAT_FILES=$( awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}' ) -mix format "$FORMAT_FILES" - -git add "$FORMAT_FILES" +if [ -n "$FORMAT_FILES" ]; then + mix format "$FORMAT_FILES" + git add "$FORMAT_FILES" +fi diff --git a/specs/nodejs/template/.githooks/pre-commit b/specs/nodejs/template/.githooks/pre-commit index b0d95f1..4036ff9 100755 --- a/specs/nodejs/template/.githooks/pre-commit +++ b/specs/nodejs/template/.githooks/pre-commit @@ -6,6 +6,7 @@ FORMAT_FILES=$( awk '$1 != "D" && $2 ~ /\.jsx?$|\.tsx?$/ {print $NF}' ) -prettier --write "$FORMAT_FILES" - -git add "$FORMAT_FILES" +if [ -n "$FORMAT_FILES" ]; then + prettier --write "$FORMAT_FILES" + git add "$FORMAT_FILES" +fi diff --git a/specs/phoenix/template/.githooks/pre-commit b/specs/phoenix/template/.githooks/pre-commit index 1fef035..0b93003 100755 --- a/specs/phoenix/template/.githooks/pre-commit +++ b/specs/phoenix/template/.githooks/pre-commit @@ -6,13 +6,17 @@ MIX_FILES=$( awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}' ) +if [ -n "$MIX_FILES" ]; then + mix format "$MIX_FILES" + git add "$MIX_FILES" +fi + WEB_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.jsx?$|\.tsx?$/ {print $NF}' ) -mix format "$MIX_FILES" - -prettier --write "$WEB_FILES" - -git add "$MIX_FILES" "$WEB_FILES" +if [ -n "$WEB_FILES" ]; then + prettier --write "$WEB_FILES" + git add "$WEB_FILES" +fi diff --git a/specs/poetry/template/.githooks/pre-commit b/specs/poetry/template/.githooks/pre-commit index 4f0d595..ffc73b0 100644 --- a/specs/poetry/template/.githooks/pre-commit +++ b/specs/poetry/template/.githooks/pre-commit @@ -6,6 +6,7 @@ FORMAT_FILES=$( awk '$1 != "D" && $2 ~ /\.py$/ {print $NF}' ) -black --quiet "$FORMAT_FILES" - -git add "$FORMAT_FILES" +if [ -n "$FORMAT_FILES" ]; then + black --quiet "$FORMAT_FILES" + git add "$FORMAT_FILES" +fi