mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 19:07:02 +01:00
Wires the shared gate (~/utils/scripts/check_file_length.sh) into a new .pre-commit-config.yaml as a local hook, checking only the files in the commit and failing rather than warning. No baseline, no allowlist. The repo had a hand-written .git/hooks/pre-commit running two checks; both are ported verbatim into the config rather than dropped, with the version bump ordered last so it cannot rewrite pubspec.yaml for a commit a gate is still about to reject. scripts/install_hooks.sh now installs pre-commit (and removes the legacy hook) instead of writing its own. .github/workflows/file-length.yml runs the same check on push, kept separate from release-apk.yml so an over-long file fails lint rather than blocking an APK release. Splits the four cleanest violations, all behaviour-preserving: note_template.dart 370 -> 203 + parser (186) firebase_backend.dart 308 -> barrel (24) + project/store/client port_guard.dart 315 -> 232 + linux_system_probe (100) notes_list_screen.dart 698 -> 225 + 5 widget/nav files Where a file had external callers, the original path stays as a barrel that re-exports the split parts, so no call site changed. Verified: 313 tests pass, coverage identical at 99.9% / 1922 lines (per-file too -- notes_list's 281 covered lines are now 81+75+51+41+22+11), flutter analyze clean, and a staged 260-line file makes git commit fail. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
1.7 KiB
Bash
Executable File
55 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# Install this repo's git hooks.
|
|
#
|
|
# .git/hooks/ is not tracked, so a fresh clone has no hooks. Run this once
|
|
# after cloning.
|
|
#
|
|
# This repo used to write a hand-rolled .git/hooks/pre-commit here. It moved
|
|
# to the pre-commit framework when the 250-line file-length gate was added:
|
|
# three checks in one hand-written hook is the point where "just a plain
|
|
# script" stops paying for itself, and pre-commit already solves passing only
|
|
# the staged files to each check. The checks themselves are unchanged and
|
|
# still live in scripts/ -- see .pre-commit-config.yaml.
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
|
readonly REPO_ROOT
|
|
readonly HOOK="$REPO_ROOT/.git/hooks/pre-commit"
|
|
readonly LEGACY_MARKER='bump_patch_version.sh'
|
|
|
|
# The old hand-written hook has to go before pre-commit will install over it;
|
|
# pre-commit refuses to clobber a foreign hook, and leaving it would run the
|
|
# version bump twice per commit.
|
|
remove_legacy_hook() {
|
|
if [[ -e "$HOOK" ]] && grep -q "$LEGACY_MARKER" "$HOOK" \
|
|
&& ! grep -q 'pre-commit' "$HOOK"; then
|
|
rm -f "$HOOK"
|
|
echo "Removed the legacy hand-written pre-commit hook."
|
|
fi
|
|
}
|
|
|
|
ensure_pre_commit() {
|
|
if command -v pre-commit >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
echo "Installing pre-commit..."
|
|
if command -v pipx >/dev/null 2>&1; then
|
|
pipx install pre-commit
|
|
else
|
|
python3 -m pip install --user pre-commit
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
ensure_pre_commit
|
|
remove_legacy_hook
|
|
pre-commit install
|
|
echo "Installed pre-commit hooks: $HOOK"
|
|
}
|
|
|
|
main "$@"
|