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