Validating commit messages with Flutter and Lefthook
Generally [Dev] push code with hurry commit like : "fix bug", "update code", "wip", "fix" so on. I used to be like that before but now I'm not. This is the next level of acknowledgement with git tool. I think the couldn't ignore since [Dev] start contribute to Source Code Management Tools like github, gitlab, so on.
In this case, I validate git commit message with flutter (Mobile Dev). First of all, in your root flutter project :
1. Create Commit Message File β¨
In your root project create folder tools. In tools folder create file name commit_msg.dart

Note: can customise folder name & file name whatever you want.
2. Edit Commit Message File βοΈ
This is the example of commit msg file. [Dev] can customise whatever you want.

- in this file :
- validate the commit message
- have regex for validate
- check condition commit message with regex ([Dev] can customise regex)
- exit(1) : return error in git output.
3. Install LeftHook π¦
[Dev] need to install lefthook command as global in your machine. This is the first step so let install lefthook :
brew install lefthook
Okie now have lefthook in your machine. Next step [Dev] is optional, for me I use fvm with flutter. If [Dev] not use fvm it's okie.
4. Init lefthook and fvm(optional) in to the project π§

After init lefthook already [Dev] gonna see the file lefthook.yml in your project. This is the default file after run command lefthook install.

Okie let's hop next.
5. Edit lefthook file
write this code under the defaults lefthook code or replace this code with it.

Note: if [Dev] not use fvm don't include it in the command. just flutter pub run tools/commit_msg.dart {1}. {1} is the path to the temporary commit message file like .git/COMMIT_EDITMSG.
6. Test
Let's test it work or not.
This is the example I test with the invalid commit message:

This is example wit the valide commit message :

That's all. π
