Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/guardrails/work-resolve-issue-issue-7966-3f9c2a71.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Fixed

- The commit-msg convention hook no longer rejects the subjects git writes itself: `Merge ...` from `git merge` and `Revert "..."` from `git revert` now pass before the team pattern check. Every other subject is still checked.
4 changes: 3 additions & 1 deletion plugins/guardrails/git-hooks/commit-msg-convention.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# prints a notice with the resolver's diagnostic to stderr (this hook has no
# model channel): exit 1 with empty stderr is "no pattern", anything else a failure.
# Fixup, squash and amend subjects pass, as rebase --autosquash consumes them.
# So do the subjects git writes itself: `Merge ...` from git merge and
# `Revert "..."` from git revert.
# A violation prints how to fix the subject and exits 1; this hook never
# suggests skipping it.
set -uo pipefail
Expand Down Expand Up @@ -83,7 +85,7 @@ done <"$msg_file"
[[ -n "$subject" ]] || exit 0

case "$subject" in
"fixup! "* | "squash! "* | "amend! "*) exit 0 ;;
"fixup! "* | "squash! "* | "amend! "* | "Merge "* | 'Revert "'*) exit 0 ;;
*) ;;
esac

Expand Down
7 changes: 6 additions & 1 deletion plugins/guardrails/git-hooks/commit-msg-convention.test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Contract tests for the guardrails commit-msg entry (git-hooks/commit-msg-convention.sh):
# a subject off the team's tracked subject_pattern fails, a matching one and
# the autosquash forms pass, no tracked pattern (or a non-ERE one) enforces
# the autosquash forms and git's own Merge and Revert subjects pass, no tracked pattern (or a non-ERE one) enforces
# nothing, a missing resolver never blocks blind, and the plugin's vendored
# installer wires the entry so `git commit` runs it from the installed copy.
# test-scope: plugins/guardrails/git-hooks/entries.json plugins/guardrails/hooks/resolve-convention-pattern.sh plugins/guardrails/lib/git-hooks/install.mjs
Expand Down Expand Up @@ -86,6 +86,11 @@ expect "core.commentChar: a # line is the subject" 1 "$(msg "$REPO" $'# not a co
new_repo "$CC"
expect "Conventional Commits keyword: feat: passes" 0 "$(msg "$REPO" "feat: add thing")"
expect "Conventional Commits keyword: a plain subject fails" 1 "$(msg "$REPO" "junk subject")"
expect "Conventional Commits keyword: a git-written Merge subject passes" 0 "$(msg "$REPO" "Merge branch 'x'")"
expect "Conventional Commits keyword: a git-written Revert subject passes" 0 "$(msg "$REPO" 'Revert "feat: y"')"
expect "Conventional Commits keyword: update stuff still fails" 1 "$(msg "$REPO" "update stuff")"
expect "Conventional Commits keyword: Merging without the git form still fails" 1 "$(msg "$REPO" "Mergers and acquisitions")"
expect "Conventional Commits keyword: Revert without a quote still fails" 1 "$(msg "$REPO" "Revert the thing")"
err="$( (cd "$REPO" && printf 'junk subject\n' >"$WORK/msg" && bash "$CHECK" "$WORK/msg") 2>&1 >/dev/null)"
expect "the failure names the subject and how to fix it, never a skip" "yes|no" \
"$(grep -q 'subject: junk subject' <<<"$err" && echo yes || echo no)|$(grep -qi 'no-verify' <<<"$err" && echo yes || echo no)"
Expand Down
Loading