Git::Validate - Validate Git Commit Messages
version 0.001001
use Git::Validate; my $validator = Git::Validate->new; my $errors = $validator->validate_commit('HEAD'); die "$errors\n" if $errors;
Or if you want to be all classy and modern:
for $e (@{$errors->errors}) { warn $e->line . " longer than " . $e->max_length . " characters!\n" if $e->isa('Git::Validate::Error::LongLine') }
While many users apparently don't know it, there are actual correct ways to write a git commit message. For a good summary of why, read this blog post.
git
This module does its best to automatically check commit messages against The Rules. The current automatic checks are:
First line should be 50 or fewer characters
Second line should be blank
Third and following lines should be less than 72 characters
validate_commit
my $errors = $validator->validate_commit('HEAD');
returns "ERRORS" for a given commit
validate_message
my $errors = $validator->validate_message($commit_message);
returns "ERRORS" for a given message
The object containing errors conveniently stringifies and boolifies. If you need more information, please please please don't try to parse the returned strings. Instead, note that the errors returned are a set of objects. These are the objects you can check for:
stringifies
boolifies
Git::Validate::Error::LongLine
Git::Validate::Error::MissingBreak
The objects can be accessed with the errors method, which returns an arrayref. The objects have line and line_number methods. The ::LongLine objects have a max_length method as well.
errors
line
line_number
::LongLine
max_length
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
This software is copyright (c) 2015 by Arthur Axel "fREW" Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Git::Validate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Validate
CPAN shell
perl -MCPAN -e shell install Git::Validate
For more information on module installation, please visit the detailed CPAN module installation guide.