#!/usr/bin/env bash
# 拦截提交包含签名凭据的 build-profile.json5。
# Block commits that add signing credentials to build-profile.json5.
# 详见 docs/build-deploy.md 的「签名管理」章节。

set -u

FILE="build-profile.json5"

# 仅当本次提交要改动 build-profile.json5 时才检查
if git diff --cached --quiet -- "$FILE"; then
  exit 0
fi

# 读取暂存区版本，检测签名敏感字段
if git show ":$FILE" | grep -qE '"(keyPassword|storePassword|certpath|storeFile|keyAlias|signAlg)"'; then
  cat >&2 <<'EOF'

❌ 已拦截提交：build-profile.json5 中含签名凭据（keyPassword / storePassword / certpath / …）。
   signingConfigs 必须保持为空 [] 才能提交。
   处理办法：
     - 若只是本地 DevEco 自动签名产生的：先取消暂存，再还原为空
         git reset HEAD build-profile.json5
         git checkout -- build-profile.json5
     - 确需本地跑真机：保持该改动「未提交」即可，不要 git add 它。
   如确实要临时绕过（不建议）：git commit --no-verify
   详见 docs/build-deploy.md 的「签名管理」章节。
EOF
  exit 1
fi

exit 0
