From 8c001ee8d29177a78f91ae9f3067a1f6f2d0f7f8 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 18 Mar 2025 00:33:56 +0800 Subject: [PATCH] Unset locale while pattern matching This commit resolves the "Invalid collation character" error thrown by 'grep' when validating directory names with special characters. It sets locale to "C" before running 'grep'. Change-Id: Ia005744cfc1799dff0148602bcb99d947f8c805d --- scripts/commit-msg.hook | 2 +- scripts/pre-commit.hook | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/commit-msg.hook b/scripts/commit-msg.hook index 96692fdde..f34e693fd 100755 --- a/scripts/commit-msg.hook +++ b/scripts/commit-msg.hook @@ -476,7 +476,7 @@ 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" | grep "[一-龥]") + 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" fi diff --git a/scripts/pre-commit.hook b/scripts/pre-commit.hook index 9f4dce1fd..bae4cb5ef 100755 --- a/scripts/pre-commit.hook +++ b/scripts/pre-commit.hook @@ -99,7 +99,7 @@ RETURN=0 # Disallow non-ASCII characters in workspace path workspace=$(git rev-parse --show-toplevel) -if echo "$workspace" | grep -q "[一-龥]"; then +if echo "$workspace" | LC_ALL=C grep -q "[一-龥]"; then throw "The workspace path '$workspace' contains non-ASCII characters." fi