diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index ecd768ab7..dea94ea0e 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -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 \ diff --git a/scripts/common.sh b/scripts/common.sh index 8597511eb..813196529 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,4 +1,5 @@ RED="" +GREEN="" YELLOW="" BLUE="" WHITE="" @@ -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' diff --git a/scripts/pre-commit.hook b/scripts/pre-commit.hook index 951943f40..50a951903 100755 --- a/scripts/pre-commit.hook +++ b/scripts/pre-commit.hook @@ -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 @@ -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" @@ -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 diff --git a/scripts/pre-push.hook b/scripts/pre-push.hook index ed2f969bb..86ec95814 100755 --- a/scripts/pre-push.hook +++ b/scripts/pre-push.hook @@ -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 "=============" @@ -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.