From 4c31eea66c2e13cde9039ce2b42a119733842ee3 Mon Sep 17 00:00:00 2001 From: levisyin Date: Tue, 23 Jan 2024 18:39:29 +0800 Subject: [PATCH 1/2] refactor: improve git hook script --- Makefile | 1 + scripts/hooks/pre-commit.sh | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 9e04e87dc05..96bc12dda24 100644 --- a/Makefile +++ b/Makefile @@ -317,6 +317,7 @@ setup-pre-commit: @cp .git/hooks/pre-commit .git/hooks/pre-commit.bak 2>/dev/null || true @echo "Installing pre-commit hook..." @ln -sf ../../scripts/hooks/pre-commit.sh .git/hooks/pre-commit + @echo "Pre-commit hook was installed at .git/hooks/pre-commit" #? lint: Run golangci-lint on all modules lint: diff --git a/scripts/hooks/pre-commit.sh b/scripts/hooks/pre-commit.sh index e8e4a700ffe..dee90070dfe 100755 --- a/scripts/hooks/pre-commit.sh +++ b/scripts/hooks/pre-commit.sh @@ -22,14 +22,13 @@ function check_golangci_lint_version(){ } function lint_and_add_modified_go_files() { - local go_files="$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$)" - for f in $go_files; do - local dir_name="$(dirname $f)" + local go_file_dirs="$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$ | xargs dirname | sort | uniq)" + for dir_name in $go_file_dirs; do golangci-lint run "${dir_name}" --fix --out-format=tab --issues-exit-code=0 - echo "adding ${f} to git index" - git add $f + echo "adding ${dir_name} to git index" + git add $dir_name done } -check_golangci_lint_version +#check_golangci_lint_version lint_and_add_modified_go_files From 20f1e7d6bd07d0d9552e1d6f8a07f67bedd84146 Mon Sep 17 00:00:00 2001 From: levisyin Date: Tue, 23 Jan 2024 20:02:56 +0800 Subject: [PATCH 2/2] revert debug changes --- scripts/hooks/pre-commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/hooks/pre-commit.sh b/scripts/hooks/pre-commit.sh index dee90070dfe..8c7cf14ae9e 100755 --- a/scripts/hooks/pre-commit.sh +++ b/scripts/hooks/pre-commit.sh @@ -30,5 +30,5 @@ function lint_and_add_modified_go_files() { done } -#check_golangci_lint_version +check_golangci_lint_version lint_and_add_modified_go_files