diff --git a/CMakeLists.txt b/CMakeLists.txt index 19a973357..22ab45fa1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100644 index 000000000..914619009 --- /dev/null +++ b/scripts/hooks/pre-commit @@ -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 +