Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat: add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaaai0809 committed Mar 29, 2024
1 parent ba19f13 commit f842a29
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

THIS_FILE_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "${THIS_FILE_DIR}/.." && pwd)"
cd ${PROJECT_DIR}

before_diff_bytes=`git diff | wc -c`
diff_files=`git diff --name-only HEAD ${PROJECT_DIR}`

for diff_file in "$diff_files"
do
if echo "$diff_file" | grep -q '\.go$'; then
go fmt "$diff_file"

echo "\\033[0;32m[DONE]\\033[0m Formatting golang code $diff_file"
fi
done

after_diff_bytes=`git diff | wc -c`

diff_bytes=`expr $after_diff_bytes \- $before_diff_bytes`
if [ $diff_bytes -gt 0 ]; then
echo "\\033[0;32m[DONE]\\033[0m Complete Formatting golang code !"

exit 1
fi

0 comments on commit f842a29

Please sign in to comment.