# Copyright (c) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #!/bin/sh for FILE in $(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(cpp|hpp)$') do git diff --cached --unified=0 "$FILE" | awk '/^\+[ ]*const std::string CommonEventSupport::/{ match($0, /CommonEventSupport::([A-Za-z_]+) =/, arr); print arr[1]; }' | while read -r CONSTANT_NAME do if ! git diff --cached --unified=0 "$FILE" | grep -q "commonEventSupport_.emplace_back($CONSTANT_NAME)" then echo "Error: 在文件 $FILE 中,新增的常量字符串 $CONSTANT_NAME 未被添加到 commonEventSupport_.emplace_back 中。" echo "请确保每个新增的常量字符串都被正确添加到 commonEventSupport_ 中。" exit 1 fi done done exit 0