todo-app/scripts/install_hooks.sh
Krzysztof kuhy Rudnicki a494843d0a
Some checks are pending
release-apk / release (APK) (push) Waiting to run
Bump the patch version on every commit
The AUR package sources the clean vX.Y.Z tag the release workflow cuts, but
that tag only moves when pubspec.yaml's version changes by hand -- so it sat on
v1.0.0 while HEAD moved 8 commits ahead, and the package advertised a stale
tree. Bumping the patch per commit keeps that tag tracking HEAD.

Patch, not minor: minor/major are the "how much broke" signal, and
auto-incrementing them on every commit throws that away (and reaches absurd
numbers within a year).

Two guards keep the number honest, both covered by a scratch-repo run:
re-running the hook over the same staged change is idempotent, because the bump
is computed from the last COMMITTED version rather than the working tree; and a
rebase/merge/cherry-pick in progress is skipped, so replayed commits don't each
inflate it.

.git/hooks is untracked, so scripts/install_hooks.sh makes the hook
reproducible on a fresh clone -- this repo has no pre-commit framework.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aoa1nKWRrAbowz7Hfd3tgL
2026-08-09 23:03:59 +02:00

35 lines
1.0 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. Unlike habit_stack and diet-guard, this repo does not use the
# pre-commit framework (its quality gate is CI), so the hook is a plain script.
# ============================================================================
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel)"
readonly REPO_ROOT
readonly HOOK="$REPO_ROOT/.git/hooks/pre-commit"
main() {
if [[ -e "$HOOK" ]] && ! grep -q 'bump_patch_version.sh' "$HOOK"; then
echo "Error: $HOOK exists and is not ours; refusing to clobber it." >&2
exit 1
fi
cat > "$HOOK" <<'HOOK_BODY'
#!/bin/bash
# Installed by scripts/install_hooks.sh — see that file.
set -euo pipefail
exec bash "$(git rev-parse --show-toplevel)/scripts/bump_patch_version.sh"
HOOK_BODY
chmod 755 "$HOOK"
echo "Installed pre-commit hook: $HOOK"
}
main "$@"