Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve the git hook script #5689

Merged
merged 8 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions scripts/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ 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
}

Expand Down
Loading