Skip to content

Fixed commit-msg hook warning on emoji-prefixed commits#28400

Merged
9larsons merged 1 commit into
mainfrom
fix/commit-msg-emoji-detection
Jun 6, 2026
Merged

Fixed commit-msg hook warning on emoji-prefixed commits#28400
9larsons merged 1 commit into
mainfrom
fix/commit-msg-emoji-detection

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

@9larsons 9larsons commented Jun 6, 2026

Problem

The commit-msg hook's "user-facing changes should start with an emoji" check never recognizes an actual emoji, so the warning fires on every commit that correctly follows our emoji convention.

In .github/hooks/commit-msg.bash it tested the first word against POSIX [[:punct:]]:

if [[ ! "$first_word" =~ ^[[:punct:]] ]]; then
    echo "Warning: User-facing changes should start with an emoji"
fi

Emoji (🐛 ✨ 🎨 🌐 💡) are not punctuation, so the negated test is always true → the warning always prints. Ironically a non-emoji prefix like *Fixed or :bug: passed the check.

Solution

Detect emoji by stripping ASCII bytes from the first word and checking whether anything (a multi-byte emoji) remains:

if [[ -z "$(printf '%s' "$first_word" | LC_ALL=C tr -d '\000-\177')" ]]; then
    echo "Warning: User-facing changes should start with an emoji"
fi

tr is portable across the macOS/Linux shells contributors use, and this keeps the check a non-blocking warning.

Testing

Verified against representative subjects:

Subject Before After
🐛 Fixed … ⚠️ warns (wrong) ✅ ok
✨ Added … ⚠️ warns (wrong) ✅ ok
🌐 Updated … ⚠️ warns (wrong) ✅ ok
Fixed … (no emoji) ⚠️ warns ⚠️ warns
*Fixed … ✅ ok (wrong) ⚠️ warns

ref https://linear.app/ghost/issue/PLA-76

ref https://linear.app/ghost/issue/PLA-76

- the "user-facing changes should start with an emoji" check tested the first word against [[:punct:]], which never matches an actual emoji
- as a result the warning fired on every correctly-prefixed commit (🐛, ✨, …) while plain-punctuation prefixes like *Fixed or :bug: passed
- detect emoji by stripping ASCII bytes from the first word instead, so real emoji prefixes pass and plain-ASCII subjects still warn
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ca13ec2-9f03-410c-a537-8a3d55416336

📥 Commits

Reviewing files that changed from the base of the PR and between bde342e and e322f1f.

📒 Files selected for processing (1)
  • .github/hooks/commit-msg.bash

Walkthrough

The PR updates the emoji validation logic in the Git commit-msg hook. The hook now detects emoji in the first word of the commit subject by removing all ASCII bytes using tr under LC_ALL=C and checking whether non-ASCII bytes remain. This replaces the previous punctuation-based regex condition that could incorrectly warn on correctly formatted commits.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately describes the main change: fixing the commit-msg hook's incorrect warning behavior on emoji-prefixed commits.
Description check ✅ Passed The description thoroughly explains the problem, solution, and testing for the emoji detection fix, directly aligned with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/commit-msg-emoji-detection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@9larsons 9larsons enabled auto-merge (squash) June 6, 2026 20:03
@9larsons 9larsons merged commit 402a785 into main Jun 6, 2026
44 checks passed
@9larsons 9larsons deleted the fix/commit-msg-emoji-detection branch June 6, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant