From 74d141d7c7f1e1136205ffc7f108383f25ae6aba Mon Sep 17 00:00:00 2001 From: Michael Beutler <35310806+michaelbeutler@users.noreply.github.com> Date: Wed, 20 May 2026 12:33:08 +0200 Subject: [PATCH] fix(hooks): honor pre-commit filenames in values-check & avoid set -e abort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit values-check.sh read `git diff --cached --name-only` and, under `set -e`, the assignment aborted the script the moment grep matched nothing (e.g. when run via `pre-commit run --all-files` with nothing staged) — printing only the header and exiting 1. pre-commit already passes the matched values.yaml paths as arguments (pass_filenames defaults to true), so use "$@" when present and fall back to staged files otherwise. Add `|| true` so an empty match no longer trips `set -e`. Behaviour verified for: args passed, staged-only, clean tree (graceful skip), and invalid YAML (still rejected). --- scripts/hooks/values-check.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/hooks/values-check.sh b/scripts/hooks/values-check.sh index 715d261..dadb4d4 100755 --- a/scripts/hooks/values-check.sh +++ b/scripts/hooks/values-check.sh @@ -6,8 +6,14 @@ set -e echo "🔍 Validating values.yaml files..." -# Get changed values.yaml files -changed_values=$(git diff --cached --name-only | grep "values\.yaml$") +# pre-commit passes the matched files as arguments; fall back to staged +# values.yaml when invoked directly (e.g. as a manual git hook with no args). +# The `|| true` keeps `set -e` from aborting when grep finds no match. +if [ "$#" -gt 0 ]; then + changed_values=$(printf '%s\n' "$@" | grep "values\.yaml$" || true) +else + changed_values=$(git diff --cached --name-only | grep "values\.yaml$" || true) +fi if [ -z "$changed_values" ]; then echo "✅ No values.yaml changes detected"