From e6629be4b74e21f48b418bc13f63276350d0eca7 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Fri, 23 May 2025 12:13:39 +0800 Subject: [PATCH] NEW:add pre-commit for check error incorrect use like WxColour(0x00AE42) jira: none Change-Id: Id35873426f9b615a3a763f18cb78133a521b19a6 --- CMakeLists.txt | 8 ++++++++ scripts/hooks/pre-commit | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 scripts/hooks/pre-commit 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 +