'How to validate git commit message for Java?
We are on Java Spring project and we need to validate commit message if it is suitable to commit convention which is expressed by Commit Guideline or Conventional Commits
I know there is a git hook(commit-msg) for this but I don't think I am able to check all conditions on above links and if I write these conditions I am not sure everyone who pulls my changes will be effected with these changes.
What I want is something like Husky for Java projects.
Solution 1:[1]
am not sure everyone who pulls my changes will be effected with these changes
You're correct. They'll need to install any client side hooks for them to take effect.
You could consider a Server Side Hook if your hosting provider supports it.
I don't think I am able to check all conditions on above links
How you implement your checks are a separate issue. I'm sure you can grep / sed / awk your way to a functional linter for your commit messages.
Solution 2:[2]
Late in the game, but perhaps still useful. If you can code in a friendly language (Python, NodeJS ...) your validation, perhaps using regex, you just need to call it when needed.
Then, you can make use of a git hook management tool to make your life (and team life) better, like https://pypi.org/project/hooks4git
Hope this helps.
Solution 3:[3]
Unfortunately, there's no well-known tool for managing git hooks in Java projects like there is Husky for JS.
In my team, we created a commit-msg git hook with bash. You can see the source code. We used bash because we wanted it to be language agnostic.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adam |
| Solution 2 | Lovato |
| Solution 3 | Vahid |
