Skip to content
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
27 changes: 23 additions & 4 deletions scripts/commit-msg.hook
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,29 @@ validate_commit_message() {
# ------------------------------------------------------------------------------

# Alert if the commit message appears to be written in Chinese.
# This pattern matches any Chinese character (common CJK Unified Ideographs).
MISSPELLED_WORDS=$(echo "$FULL_COMMIT_MSG" | LC_ALL=C grep "[一-龥]")
if [ -n "$MISSPELLED_WORDS" ]; then
add_warning 1 "Commit message appears to be written in Chinese: $MISSPELLED_WORDS"
# This pattern matches Chinese CJK Unified Ideographs range.
# Use proper UTF-8 handling to avoid false positives with Unicode symbols like ✓ and ✗.
if command -v python3 >/dev/null 2>&1; then
CHINESE_TEXT=$(echo "$FULL_COMMIT_MSG" | python3 -c "
import sys, re
text = sys.stdin.read()
chinese_chars = re.findall(r'[\u4e00-\u9fff]', text)
if chinese_chars:
print(''.join(chinese_chars))
")
else
# Fallback: Only detect actual Chinese character patterns if python3 is not available
CHINESE_TEXT=$(echo "$FULL_COMMIT_MSG" | grep -o "[一-龥]" 2>/dev/null || echo "")
# Filter out false positives by checking if the detected text contains actual Chinese words
if [ -n "$CHINESE_TEXT" ] && ! echo "$CHINESE_TEXT" | grep -q "[✓✗]"; then
CHINESE_TEXT="$CHINESE_TEXT"
else
CHINESE_TEXT=""
fi
fi

if [ -n "$CHINESE_TEXT" ]; then
add_warning 1 "Commit message appears to be written in Chinese: $CHINESE_TEXT"
fi

MSG_FOR_SPELLCHECK_LINE_FINDING=$(echo "$FULL_COMMIT_MSG_WITH_SPACE" | sed -E \
Expand Down
2 changes: 2 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
RED=""
GREEN=""
YELLOW=""
BLUE=""
WHITE=""
Expand All @@ -11,6 +12,7 @@ set_colors() {
# If color is forced (always) or auto and we are on a tty, enable color.
if [[ "$default_color" == "always" ]] || [[ "$default_color" == "auto" && -t 1 ]]; then
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
WHITE='\033[1;37m'
Expand Down
10 changes: 5 additions & 5 deletions scripts/pre-commit.hook
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ report_result() {
local status="$1"
local message="$2"
if [ "$status" -eq 0 ]; then
printf " ${GREEN}${NC}\n"
printf " [ ${GREEN}OK${NC} ]\n"
else
printf " ${RED}${NC}\n"
printf " [ ${RED}FAIL${NC} ]\n"
if [ -n "$message" ]; then
ERRORS_FOUND+=("$message")
fi
Expand Down Expand Up @@ -334,8 +334,8 @@ fi
# Clear the progress line
printf "\r%*s\r" 50 ""

# === SUMMARY ===
printf "\n${CYAN}=== Pre-commit Check Summary ===${NC}\n\n"
# Summary
printf "\n"

# Show file changes
printf "${CYAN}Files to be committed:${NC}\n"
Expand All @@ -359,7 +359,7 @@ done
if [ ${#ERRORS_FOUND[@]} -gt 0 ]; then
printf "\n${RED}Errors found:${NC}\n"
for error in "${ERRORS_FOUND[@]}"; do
printf " ${RED}${NC} %s\n" "$error"
printf " [ ${RED}FAIL${NC} ] %s\n" "$error"
done
fi

Expand Down
9 changes: 5 additions & 4 deletions scripts/pre-push.hook
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ run_build_checks() {
echo ""

# Clean previous build artifacts for fresh check
echo -e "${YELLOW}Cleaning previous build...${NC}"
printf "${YELLOW}Cleaning previous build...${NC}"
make clean >/dev/null 2>&1 || true
printf " [ ${GREEN}OK${NC} ]\n"

echo -e "${YELLOW}Building project...${NC}"
printf "${YELLOW}Building project...${NC}"

# Capture build output for better error reporting
build_output=$(make 2>&1)
build_result=$?

if [ $build_result -ne 0 ]; then
echo -e "${RED}Build failed!${NC}"
printf " [ ${RED}FAIL${NC} ]\n"
echo ""
echo "Build output:"
echo "============="
Expand All @@ -85,7 +86,7 @@ run_build_checks() {
return 1
fi

echo -e "${GREEN}✓ Build successful${NC}"
printf " [ ${GREEN}OK${NC} ]\n"

# Additional checks could be added here
# For example: basic tests, format checks, etc.
Expand Down