Files
claude-howto/ja/06-hooks/pre-commit.sh
T
Luong NGUYENandGitHub b9a973bf32 docs: accuracy pass against Claude Code v2.1.220 (#155)
Internal accuracy pass against v2.1.220 — no missing upstream features, but broken example code, disagreeing counts, and metadata drift.

Functional fixes: pre-commit.sh now exits 2 so it actually blocks; dependency-check.sh reads file_path from stdin JSON instead of $1; database-mcp.json uses ${DATABASE_URL}; broken fences repaired; three command templates had invalid skill names.

Factual corrections: /fork and /subtask unswapped and /subtask added; /fewer-permission-prompts; permissions.defaultMode; dontAsk/auto unreversed; 31 hook events verified name-by-name; subagent depth 3; skill precedence enterprise > project > personal; /output-style removed not deprecated; permissionDecision gained defer.

Follow-up review fixed defects the pass left behind: zh/vi headers claiming 31 events above 25-name lists, a surviving hardcoded DB credential in the MCP README examples, an unbalanced fence swallowing a metadata footer, and non-canonical tool names. All four translated CATALOG summary tables were recounted so their arithmetic holds.

Full detail in CHANGELOG.md under v2.1.220-r2.
2026-08-04 15:41:12 +07:00

55 lines
1.8 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
# コミット前にテストを実行する
# フック:PreToolUsematcher: Bash)— コマンドが git commit か判定する
# 注:「PreCommit」フックイベントは存在しない。PreToolUse と Bash matcher の組み合わせで
# コマンドを検査し、git commit を検出する。
#
# 終了コード:2 はツール呼び出しをブロックし、stderr の内容をブロック理由として提示する。
# それ以外の非ゼロ値は「ブロックしないエラー」であり、コミットはそのまま続行してしまう。
# 出典:https://code.claude.com/docs/en/hooks
echo "🧪 コミット前にテストを実行しています..."
# package.json の有無を確認(Node.js プロジェクト)
if [ -f "package.json" ]; then
if grep -q "\"test\":" package.json; then
npm test
if [ $? -ne 0 ]; then
echo "❌ テスト失敗。コミットをブロックします。" >&2
exit 2
fi
fi
fi
# pytest が使えるか確認(Python プロジェクト)
if [ -f "pytest.ini" ] || [ -f "setup.py" ]; then
if command -v pytest &> /dev/null; then
pytest
if [ $? -ne 0 ]; then
echo "❌ テスト失敗。コミットをブロックします。" >&2
exit 2
fi
fi
fi
# go.mod の有無を確認(Go プロジェクト)
if [ -f "go.mod" ]; then
go test ./...
if [ $? -ne 0 ]; then
echo "❌ テスト失敗。コミットをブロックします。" >&2
exit 2
fi
fi
# Cargo.toml の有無を確認(Rust プロジェクト)
if [ -f "Cargo.toml" ]; then
cargo test
if [ $? -ne 0 ]; then
echo "❌ テスト失敗。コミットをブロックします。" >&2
exit 2
fi
fi
echo "✅ 全テスト合格。コミットを続行します。"
exit 0