tree-sitter grammar for git commit messages
- C 82.6%
- Tree-sitter Query 8.9%
- JavaScript 6.8%
- Just 1.7%
Tree-Sitter Grammar to Parse Git Commit Messages
This repository contains a tree-sitter grammar to parse the git commit
message. It detects the basic structure (subject, message, trailers, comments)
as well as special keywords (such as fixup! and squash!) and conventional
commit syntax.
See Also
- tree-sitter-gitcommit by @gbprod is a more feature rich grammar to parse git commit messages
- [tree-sitter-git-rebase by @the-mikedavis] is a grammar to parse git's interactive rebase file
Motivation
Since there already is tree-sitter-gitcommit, why bother writing a competing grammar?
- The parser in tree-sitter-gitcommit is huge
- Its source is over 3 MiB or 88,000 lines of code and the compiled library is larger than the one of the rust grammar
- Building for WASM reliably triggers the OOM reaper, even with 64 GiB RAM
- This grammar is tiny by comparison
- Maintainability
- tree-sitter-gitcommit is parsing against long known phrases instead of the structure
- each localization needs to be added by hand
- if git fixes a typo in a message, the grammar needs to change
- the inability to build WASM makes debugging using the playground impossible
- Features
- Many git forges markdown in commit messages and adding injection queries for that helps me a lot