datai/datai-scenes/datai-scene-salesforce/.githooks/pre-commit

43 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# pre-commit钩子检查代码变更是否包含docs链接
set -e
echo "=== 运行pre-commit检查 ==="
# 检查是否有文件变更
if git diff --cached --name-only | grep -q "\.java$\|\.md$\|\.xml$"; then
echo "检查代码变更是否包含docs链接..."
# 获取变更的文件列表
changed_files=$(git diff --cached --name-only | grep -E "\.java$\|\.md$\|\.xml$")
# 检查每个变更的文件是否包含docs链接
has_docs_link=false
for file in $changed_files; do
if git show :"$file" | grep -q "docs/" && ! echo "$file" | grep -q "docs/"; then
echo "✓ 文件 $file 包含docs链接"
has_docs_link=true
fi
done
# 如果是文档文件变更检查是否更新了docs/index.md
if echo "$changed_files" | grep -q "docs/"; then
if ! echo "$changed_files" | grep -q "docs/index.md"; then
echo "警告文档文件已变更但未更新docs/index.md索引"
echo "请确保在docs/index.md中添加或更新对应的文档链接"
else
echo "✓ docs/index.md已更新"
fi
fi
else
echo "✓ 无代码文件变更"
fi
# 运行验证脚本的部分检查
echo "\n运行文档结构检查..."
bash scripts/verify.sh 2>&1 | grep -E "(错误|✓)"
echo "\n=== pre-commit检查完成 ==="