diff --git a/lib/Git/Hooks.pm b/lib/Git/Hooks.pm index 909df8b..62acf1a 100644 --- a/lib/Git/Hooks.pm +++ b/lib/Git/Hooks.pm @@ -1278,6 +1278,13 @@ is useful if you want to enable a plugin globally and only disable it for some repositories. You can even re-enable it later, if you want, by mentioning it again without the prefix. +Plugins can be OR-ed by separating them with a pipe (C<|>) instead of a space. + + [githooks] + plugin = CheckFile|CheckJira CheckWhitespace + +In this case CheckWhitespace C either CheckFile C CheckJira has to match. + =head2 [DEPRECATED after v3.3.0] disable PLUGIN... B Please, use the C option with an diff --git a/lib/Git/Repository/Plugin/GitHooks.pm b/lib/Git/Repository/Plugin/GitHooks.pm index 6fbc039..69334d8 100644 --- a/lib/Git/Repository/Plugin/GitHooks.pm +++ b/lib/Git/Repository/Plugin/GitHooks.pm @@ -384,7 +384,7 @@ sub load_plugins { my %plugins; - foreach my $plugin (map {split} $git->get_config(githooks => 'plugin')) { + foreach my $plugin (map {split /[\|\s]/} $git->get_config(githooks => 'plugin')) { my ($negation, $prefix, $basename) = ($plugin =~ /^(\!?)((?:.+::)?)(.+)/); if (exists $ENV{$basename} && ! $ENV{$basename}) { @@ -803,10 +803,11 @@ sub fault { my $colors = _githooks_colors($git); my $msg; + my $prefix; { - my $prefix = $info->{prefix} || caller; my @context; + $prefix = $info->{prefix} || caller; if (my $commit = $info->{commit}) { $commit = $commit->commit if ref $commit; # It's a Git::Repository::Log object @@ -834,7 +835,7 @@ sub fault { $msg .= "\n$colors->{details}$details$colors->{reset}\n\n"; } - push @{$git->{_plugin_githooks}{faults}}, $msg; + push @{$git->{_plugin_githooks}{faults}}, {msg => $msg, plugin => ($prefix) =~ /.*Git::Hooks::(\w+)/}; # Return true to allow for the idiom: or $git->fault(...) and ; return 1; @@ -853,7 +854,18 @@ sub get_faults { $faults .= $colors->{header} . qx{$header} . "$colors->{reset}\n"; ## no critic (ProhibitBacktickOperators) } - $faults .= join("\n\n", @{$git->{_plugin_githooks}{faults}}); + my @conditions = split(" ", $git->get_config(githooks => 'plugin')); + map {s/(\||$)/(ok)$1/g} @conditions; + + foreach my $fault (@{$git->{_plugin_githooks}{faults}}) { + map {s/($fault->{plugin})\(ok\)/$1(failed)/g} @conditions; + } + + # If any parts of the condition don't have an 'OK', they've failed and we need to deny the commit + if (grep {!/\(ok\)/} @conditions) { + $faults .= join("\n\n", map {$_->{msg}} @{$git->{_plugin_githooks}{faults}}); + $faults .= "\n\nOur configured plugins as they were evaluated:\n" . join(" ", @conditions) . "\n\n"; + } if ($git->{_plugin_githooks}{hookname} =~ /^commit-msg|pre-commit$/ && ! $git->get_config_boolean(githooks => 'abort-commit')) {