From 48525b2912a56f8b707671ba67d5932549384cce Mon Sep 17 00:00:00 2001 From: MaxymVlasov Date: Mon, 7 Jul 2025 14:44:40 +0300 Subject: [PATCH 1/3] fix: Regression which incorrectly handle `pre-commit run -a`, that causes multiply hooks runs --- hooks/_common.sh | 4 ++-- hooks/terraform_docs.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 7281b0244..2d2d2894b 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -176,9 +176,9 @@ function common::is_hook_run_on_whole_repo { local all_files_that_can_be_checked if [ -z "$excluded_files" ]; then - all_files_that_can_be_checked=$(git ls-files | sort | grep -e "$included_files" | tr '\n' ' ') + all_files_that_can_be_checked=$(git ls-files | sort | grep -E "$included_files" | tr '\n' ' ') else - all_files_that_can_be_checked=$(git ls-files | sort | grep -e "$included_files" | grep -v -e "$excluded_files" | tr '\n' ' ') + all_files_that_can_be_checked=$(git ls-files | sort | grep -E "$included_files" | grep -v -E "$excluded_files" | tr '\n' ' ') fi if [ "$files_to_check" == "$all_files_that_can_be_checked" ]; then diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 02d012f83..7644b5e4c 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -187,7 +187,7 @@ function terraform_docs { config_file_no_color="$config_file$(date +%s).yml" if [ "$PRE_COMMIT_COLOR" = "never" ] && - [[ $(grep -e '^formatter:' "$config_file") == *"pretty"* ]] && + [[ $(grep -E '^formatter:' "$config_file") == *"pretty"* ]] && [[ $(grep ' color: ' "$config_file") != *"false"* ]]; then cp "$config_file" "$config_file_no_color" From bafa6635606e8f6f5bd81fe99a391a2b12245768 Mon Sep 17 00:00:00 2001 From: MaxymVlasov Date: Mon, 7 Jul 2025 15:12:26 +0300 Subject: [PATCH 2/3] trivy: Unify falier mode in `run_hook_on_whole_repo` as for `per_dir_hook_unique_part` --- hooks/terraform_trivy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/terraform_trivy.sh b/hooks/terraform_trivy.sh index fb4a529a0..d607d67a5 100755 --- a/hooks/terraform_trivy.sh +++ b/hooks/terraform_trivy.sh @@ -65,7 +65,7 @@ function run_hook_on_whole_repo { local -a -r args=("$@") # pass the arguments to hook - trivy conf "$(pwd)" "${args[@]}" + trivy conf "$(pwd)" --exit-code=1 "${args[@]}" # return exit code to common::per_dir_hook local exit_code=$? From 11e74ae4960af576873d56438525cc6b10a8345e Mon Sep 17 00:00:00 2001 From: MaxymVlasov Date: Mon, 7 Jul 2025 20:42:25 +0300 Subject: [PATCH 3/3] Apply review suggestions --- hooks/_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 2d2d2894b..c63918033 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -176,9 +176,9 @@ function common::is_hook_run_on_whole_repo { local all_files_that_can_be_checked if [ -z "$excluded_files" ]; then - all_files_that_can_be_checked=$(git ls-files | sort | grep -E "$included_files" | tr '\n' ' ') + all_files_that_can_be_checked=$(git ls-files | sort | grep -E -- "$included_files" | tr '\n' ' ') else - all_files_that_can_be_checked=$(git ls-files | sort | grep -E "$included_files" | grep -v -E "$excluded_files" | tr '\n' ' ') + all_files_that_can_be_checked=$(git ls-files | sort | grep -E -- "$included_files" | grep -v -E -- "$excluded_files" | tr '\n' ' ') fi if [ "$files_to_check" == "$all_files_that_can_be_checked" ]; then