Skip to content

Commit

Permalink
refactor: improve the git hook script (cosmos#5689)
Browse files Browse the repository at this point in the history
* refactor: improve git hook script

* revert debug changes

---------

Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
levisyin and crodriguezvega authored Feb 2, 2024
1 parent 8e4f966 commit 97a52e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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

0 comments on commit 97a52e3

Please sign in to comment.