Git 管理対象の hook として以下を導入した。
githooks/pre-committools/unicode_scan.shGit 側は以下を設定した。
git config --local core.hooksPath githooks
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}" || exit 1
./tools/unicode_scan.sh .
#!/usr/bin/env bash
set -euo pipefail
TARGET_DIR="${1:-.}"
echo "[*] Scanning for invisible Unicode characters under: ${TARGET_DIR}"
if grep -P -nR \
--exclude-dir=.git \
--exclude-dir=.venv \
--exclude-dir=venv \
--exclude='*.vault' \
--exclude='*.retry' \
--exclude='*.png' \
--exclude='*.jpg' \
--exclude='*.jpeg' \
--exclude='*.gif' \
--exclude='*.pdf' \
--exclude='*.gz' \
--exclude='*.zip' \
--exclude='*.tar' \
--exclude='*.tar.gz' \
--exclude='*.tgz' \
--exclude='*.7z' \
--exclude='*.jar' \
--exclude='*.war' \
--exclude='*.mp3' \
--exclude='*.mp4' \
--exclude='*.iso' \
"[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}\x{FEFF}]" \
"${TARGET_DIR}"
then
echo "[!] Invisible Unicode detected"
exit 1
else
echo "[OK] No invisible Unicode detected"
fi
原因:
対応:
確認:
git config --local --get core.hooksPath
ls -l githooks/pre-commit
chmod +x tools/unicode_scan.sh