Commit Gate
A spec for a hook that refuses a commit an agent did not gate on its check (Gate Commits On Exit Codes, Verify Staging Before Committing).
Where It Runs
- Before every shell command an agent runs, where the agent's app supports such a hook.
- It reads the command and nothing else, and refuses it with a message that says what to do instead.
What It Does
- It refuses a
git commitor agit tagthat runs right after a;. - It refuses one that follows a check piped into
grep,tailorheadanywhere before it in the command, since the pipe hides the check's exit code, saved in a variable or not. - It refuses a
git committhat follows agit addin the same command, since the staged list was not read in between. - It ignores what is quoted, a heredoc body, a command substitution and a comment, so a message with a
;in it passes. - A
git tagthat only lists tags passes, piped onward or not, a listing option such as--sortor--containsincluded.
The Check
npm test && git commit -m xpasses.npm test; git commit -m xrefuses.npm test | tail -3 && git commit -m xrefuses.npm test >check.log 2>&1; rc=$?; [ $rc -eq 0 ] && git commit -m xpasses.npm test | tail -3; rc=$?; [ $rc -eq 0 ] && git commit -m xrefuses.git add a && git commit -m xrefuses.git commit -m "a; b"passes.- A commit message given in a heredoc that holds a
;passes. lspasses.ls; git tag -lpasses.ls; git tag | sortpasses.ls; git tag --sort=-v:refnamepasses.ls; git tag v1refuses.