Skip to content

Commit

Permalink
CheckLog: make body-max-width disregard indented lines
Browse files Browse the repository at this point in the history
Only lines starting with a non-whitespace character should be checked
against the limit. It's a common style to quote things with indented
lines and we like to make those lines free of any restriction in order
to keep the quoted text authentic.
  • Loading branch information
gnustavo committed Apr 27, 2015
1 parent 218bdf5 commit 3cef2dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/Git/Hooks/CheckLog.pm
Expand Up @@ -165,8 +165,7 @@ sub body_errors {
return 0 unless defined $body && length $body;

if (my $max_width = $git->get_config($CFG => 'body-max-width')) {
my $toobig = $max_width + 1;
if (my @biggies = ($body =~ /^(.{$toobig,})/gm)) {
if (my @biggies = grep {/^\S/} grep {length > $max_width} split(/\n/, $body)) {
my $theseare = @biggies == 1 ? "this is" : "these are";
$git->error($PKG,
"commit $id log body lines should be at most $max_width characters wide, but $theseare bigger",
Expand Down Expand Up @@ -388,6 +387,11 @@ This option specifies a limit to the width of the commit log message's
body lines, in characters. It's 72 by default. If you set it to 0 the
plugin imposes no limit on the body line's width.
Only lines starting with a non-whitespace character are checked against the
limit. It's a common style to quote things with indented lines and we like
to make those lines free of any restriction in order to keep the quoted text
authentic.
=head2 githooks.checklog.match [!]REGEXP
This option may be specified more than once. It defines a list of
Expand Down
11 changes: 10 additions & 1 deletion t/02-check-log.t
Expand Up @@ -4,7 +4,7 @@ use 5.010;
use strict;
use warnings;
use lib 't';
use Test::More tests => 23;
use Test::More tests => 24;
use Path::Tiny;

BEGIN { require "test-functions.pl" };
Expand Down Expand Up @@ -152,6 +152,15 @@ Body first line.
The previous line has 73 characters.
EOF

check_can_commit('allow body with large quoted line', <<'EOF');
Title
Body first line.
123456789012345678901234567890123456789012345678900123456789001234567890123
The previous line has 77 characters.
EOF

$repo->command(config => 'githooks.checklog.body-max-width', 0);

check_can_commit('allow large body', <<'EOF');
Expand Down

0 comments on commit 3cef2dd

Please sign in to comment.