From b52c8ee8a8453cca0defa6fa14394b0d64286da0 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 14 Sep 2025 02:14:40 +0800 Subject: [PATCH 1/2] Replace Unicode symbol with ASCII status indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This replaces ✓/✗ symbols with [ OK ]/[ FAIL ] for better compatibility. It also standardizes printf formatting in git pre-push hook, ensuring brackets display in normal color, only status text colored. Change-Id: I4ba4f74acd36895b415648fddd9d04a1498858e0 --- scripts/common.sh | 2 ++ scripts/pre-commit.hook | 10 +++++----- scripts/pre-push.hook | 9 +++++---- 3 files changed, 12 insertions(+), 9 deletions(-) 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. From 064429e51d533d743a8112502f25e61965ee8e88 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 14 Sep 2025 02:16:44 +0800 Subject: [PATCH 2/2] Fix false positive Chinese detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit-msg hook was incorrectly flagging Unicode symbols like ✓ and ✗ as "Chinese characters" due to improper locale handling with LC_ALL=C. It uses Python3 with proper Unicode regex '[\u4e00-\u9fff]' for accurate detection adds fallback logic for systems without Python3, filtering out known Unicode symbols from false positive matches. Change-Id: I9b6b446b8f6df7a4b081f51c53204d3c97274607 --- scripts/commit-msg.hook | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) 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 \