From 3cef2dd3f3cad60a6c5eced8f2952c0fb845b751 Mon Sep 17 00:00:00 2001 From: "Gustavo L. de M. Chaves" Date: Fri, 24 Apr 2015 22:31:09 -0300 Subject: [PATCH] CheckLog: make body-max-width disregard indented lines 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. --- lib/Git/Hooks/CheckLog.pm | 8 ++++++-- t/02-check-log.t | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Git/Hooks/CheckLog.pm b/lib/Git/Hooks/CheckLog.pm index 84792ef..3727f95 100644 --- a/lib/Git/Hooks/CheckLog.pm +++ b/lib/Git/Hooks/CheckLog.pm @@ -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", @@ -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 diff --git a/t/02-check-log.t b/t/02-check-log.t index 30084a3..55882a0 100755 --- a/t/02-check-log.t +++ b/t/02-check-log.t @@ -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" }; @@ -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');