mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-10-18 19:10:30 +08:00
just: Introduce commit-msg hook for typos
Add a `commit-msg` hook to continuously run `typos` against the COMMIT_MSG.
This commit is contained in:
committed by
Fintan Halpenny
parent
f6bf13422d
commit
179a080867
@@ -1,4 +1,4 @@
|
||||
hooks := "pre-commit pre-push post-checkout"
|
||||
hooks := "pre-commit pre-push post-checkout commit-msg"
|
||||
hook-script := "scripts/git-hook-template.sh"
|
||||
|
||||
WARN := "⚠️ " + YELLOW + BOLD
|
||||
@@ -14,6 +14,12 @@ default: check-hooks
|
||||
[group('hooks')]
|
||||
post-checkout:
|
||||
|
||||
# Run commit-msg checks
|
||||
[group('hooks')]
|
||||
commit-msg file: (verify-tool "typos" "typos-cli")
|
||||
@echo "{{CHECK}}Checking commit message for typos...{{NORMAL}}"
|
||||
@NORMAL="{{NORMAL}}" WARN="{{WARN}}" scripts/just/commit-msg.sh "{{file}}"
|
||||
|
||||
# Run pre-commit checks
|
||||
[group('hooks')]
|
||||
pre-commit: format-rust check-rust check-docs check-typos check-spelling check-scripts check-keywords format-nix
|
||||
|
||||
@@ -3,7 +3,7 @@ set -euo pipefail
|
||||
|
||||
readonly HOOK="${HOOK:-$(basename "$0")}"
|
||||
|
||||
if ! [[ "$HOOK" =~ ^(pre-(commit|push)|post-checkout)$ ]]
|
||||
if ! [[ "$HOOK" =~ ^(pre-(commit|push)|post-checkout|commit-msg)$ ]]
|
||||
then
|
||||
echo "Unknown hook '${HOOK}'."
|
||||
exit 1
|
||||
@@ -41,5 +41,10 @@ then
|
||||
esac
|
||||
fi
|
||||
|
||||
just "$HOOK"
|
||||
|
||||
# Execute the appropriate just recipe based on the hook name.
|
||||
if [ "$HOOK" = "commit-msg" ]
|
||||
then
|
||||
just "$HOOK" "$1"
|
||||
else
|
||||
just "$HOOK"
|
||||
fi
|
||||
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
FILE=$1
|
||||
|
||||
while ! typos "$FILE"; do \
|
||||
exec < /dev/tty; \
|
||||
echo ""; \
|
||||
printf "%sTypos found.%s (e)dit, (c)ontinue, or (a)bort? [E/c/a] " "${WARN}" "${NORMAL}"; \
|
||||
read -r response; \
|
||||
case "$response" in \
|
||||
[cC]*) exit 0 ;; \
|
||||
[aA]*) exit 1 ;; \
|
||||
*) ${EDITOR:-nano} "$FILE" ;; \
|
||||
esac; \
|
||||
done
|
||||
Reference in New Issue
Block a user