Skip to content

Commit

Permalink
Git: improve the risky words pattern and display matched risky words
Browse files Browse the repository at this point in the history
  • Loading branch information
kg8m committed Aug 17, 2024
1 parent f600897 commit 108b28c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .config/git/hooks/post-commit
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env bash
prev_diff="$(git log --max-count=1 --patch --format= | grep -E '^\+')"
risky_pattern='\b(ap|binding\.\w+|byebug|console|debugger|inspect|logger|p?ld|pp?|puts|save_and_open_(page|screenshot)|t?ld)\b'
risky_pattern='(^|(?<=\s)|(?<=;))(ap|binding\.\w+|byebug|console(?=\.)|debugger|logger(?=\.)|p?ld|pp?|puts|save_and_open_(page|screenshot)|t?ld)\b|(?<=\.)inspect\b'

if echo "${prev_diff}" | grep -E "${risky_pattern}" -q; then
if echo "${prev_diff}" | rg "${risky_pattern}" -q; then
mark=""
message="The previous diff contains risky words. Check and fix them if needed."

printf "\n%s \e[1;31m%s\e[0;37m %s\n\n" "${mark}" "${message}" "${mark}"

echo "${prev_diff}" | rg "${risky_pattern}"
fi

if [ -f "Gemfile.lock" ]; then
Expand Down

0 comments on commit 108b28c

Please sign in to comment.