NEW:add pre-commit for check error incorrect use like WxColour(0x00AE42)

jira: none
Change-Id: Id35873426f9b615a3a763f18cb78133a521b19a6
This commit is contained in:
zhou.xu 2025-05-23 12:13:39 +08:00 committed by lane.wei
parent 1ad68b38e2
commit e6629be4b7
2 changed files with 17 additions and 0 deletions

View File

@ -171,6 +171,14 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# WIN10SDK_PATH is used to point CMake to the WIN10 SDK installation directory.
# We pick it from environment if it is not defined in another way
if(WIN32)
if(EXISTS "${CMAKE_SOURCE_DIR}/scripts/hooks/pre-commit" AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
message(STATUS ".git: directory")
configure_file(
"${CMAKE_SOURCE_DIR}/scripts/hooks/pre-commit"
"${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit"
)
endif()
find_package(PkgConfig REQUIRED)
if(NOT DEFINED WIN10SDK_PATH)
if(DEFINED ENV{WIN10SDK_PATH})

9
scripts/hooks/pre-commit Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
# 检查是否有 `wxColour(0x......)` 格式的代码
if git diff --cached --name-only | xargs grep -nE 'wxColour\(0x[0-9A-Fa-f]{6}\)'; then
echo "❌ 错误:禁止直接使用 wxColour(0x......),请改用 wxColour(\"#......\") 或 wxColour(r, g, b) 格式。"
echo "违规代码位置见上方输出。"
exit 1 # 阻止提交
fi