App-GitHooks-Plugin-DetectCommitNoVerify

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "Find out when someone uses --no-verify and append the pre-commit checks to the commit message.",
   "author" : [
      "Guillaume Aubert <aubertg@cpan.org>"
   ],
   "dynamic_config" : 1,
   "generated_by" : "Module::Build version 0.4205",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Find out when someone uses --no-verify and append the pre-commit checks to the commit message.'
author:
  - 'Guillaume Aubert <aubertg@cpan.org>'
build_requires:
  Capture::Tiny: '0'
  Git::Repository: '0'
  Test::Exception: '0'
  Test::FailWarnings: '0'
  Test::More: '0.94'
  Test::Requires::Git: '1.005'
configure_requires:

README.md  view on Meta::CPAN

App-GitHooks-Plugin-DetectCommitNoVerify
========================================

[![Build Status](https://travis-ci.org/guillaumeaubert/App-GitHooks-Plugin-DetectCommitNoVerify.svg?branch=master)](https://travis-ci.org/guillaumeaubert/App-GitHooks-Plugin-DetectCommitNoVerify)
[![Coverage Status](https://coveralls.io/repos/guillaumeaubert/App-GitHooks-Plugin-DetectCommitNoVerify/badge.svg?branch=master)](https://coveralls.io/r/guillaumeaubert/App-GitHooks-Plugin-DetectCommitNoVerify?branch=master)
[![CPAN](https://img.shields.io/cpan/v/App-GitHooks-Plugin-DetectCommitNoVerify.svg)](https://metacpan.org/release/App-GitHooks-Plugin-DetectCommitNoVerify)
[![License](https://img.shields.io/badge/license-Perl%205-blue.svg)](http://dev.perl.org/licenses/)

App::GitHooks plugin to find out when someone uses --no-verify and append the
pre-commit checks to the commit message.


INSTALLATION
------------

To install this module, run the following commands:

	perl Build.PL
	./Build

lib/App/GitHooks/Plugin/DetectCommitNoVerify.pm  view on Meta::CPAN

# External dependencies.
use Capture::Tiny qw();

# Internal dependencies.
use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES );
use App::GitHooks::Hook::PreCommit;


=head1 NAME

App::GitHooks::Plugin::DetectCommitNoVerify - Find out when someone uses --no-verify and append the pre-commit checks to the commit message.


=head1 DESCRIPTION

Sometimes you just have to use C<--no-verify> to get past the checks and commit
as fast as possible. To prevent this from being too tempting, this plugin
checks when you use --no-verify and runs the pre-commit checks if you've
skipped them. It will let you commit even if the pre-commit checks fail, but it
will add their output to the commit message for posterity (and public shaming).


=head1 VERSION

Version 1.0.3

=cut

lib/App/GitHooks/Plugin/DetectCommitNoVerify.pm  view on Meta::CPAN


			# Run all the tests for the pre-commit hook.
			$changes_pass = App::GitHooks::Hook::PreCommit::run_all_tests( $local_app );
		}
	);

	if ( !$changes_pass )
	{
		# "git revert" bypasses the pre-commit hook, so we can only use use the
		# prepare-commit-msg hook to catch any show-stoppers.
		# Since prepare-commit-msg doesn't support --no-verify, we should only
		# perform the essential checks when we're analyzing a revert. Note that you
		# can still do chmod -x .git/hooks/prepare-commit-msg to force-bypass this
		# hook in this case.
		my $staged_changes = $app->get_staged_changes();
		if ( $staged_changes->is_revert() )
		{
			chomp( $stdout );
			print $stdout, "\n";
			print "\n";
			print $app->color( 'red', "Fix the errors above and use 'git commit' to complete the revert." ) . "\n";

lib/App/GitHooks/Plugin/DetectCommitNoVerify.pm  view on Meta::CPAN

You can also look for information at:

=over

=item * GitHub's request tracker

L<https://github.com/guillaumeaubert/App-GitHooks-Plugin-DetectCommitNoVerify/issues>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/app-githooks-plugin-detectcommitnoverify>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/app-githooks-plugin-detectcommitnoverify>

=item * MetaCPAN

L<https://metacpan.org/release/App-GitHooks-Plugin-DetectCommitNoVerify>

=back


=head1 AUTHOR

t/10-run.t  view on Meta::CPAN

# .githooksrc additions.
my $config = "[Test::CustomReply]\n"
	. "pre_commit = PLUGIN_RETURN_FAILED\n"
	. "pre_commit_file = PLUGIN_RETURN_FAILED\n"
	. "prepare_commit_msg = PLUGIN_RETURN_SKIPPED\n";

# List of tests to perform.
my $tests =
[
	{
		name        => 'Commit without --no-verify.',
		no_verify   => 0,
	},
	{
		name        => 'Commit with --no-verify.',
		no_verify   => 1,
	},
];

# Bail out if Git isn't available.
test_requires_git();
plan( tests => scalar( @$tests ) );

foreach my $test ( @$tests )
{
	subtest(

t/10-run.t  view on Meta::CPAN


			# Try to commit.
			my $stderr;
			my $exit_status;
			lives_ok(
				sub
				{
					$stderr = Capture::Tiny::capture_stderr(
						sub
						{
							my @args = $test->{'no_verify'}
								? ( '--no-verify' )
								: '';
							$repository->run( 'commit', '-m', 'Test message.', @args );
							$exit_status = $? >> 8;
						}
					);
					note( $stderr );
				},
				'Commit the changes.',
			);

			# Test messages printed by git hooks prior to the commit itself.
			if ( $test->{'no_verify'} )
			{
				ok(
					!defined( $stderr ) || ( $stderr !~ /\w/ ),
					'No error message is printed prior to the commit.',
				) || diag( "STDERR: >$stderr<." );
			}
			else
			{
				like(
					$stderr,

t/11-perlcompile.t  view on Meta::CPAN


			# Try to commit.
			my $stderr;
			my $exit_status;
			lives_ok(
				sub
				{
					$stderr = Capture::Tiny::capture_stderr(
						sub
						{
							$repository->run( 'commit', '-m', 'Test message.', '--no-verify' );
							$exit_status = $? >> 8;
						}
					);
				},
				'Commit the changes.',
			);
			note( $stderr )
				if $stderr;

			SKIP:



( run in 0.443 second using v1.01-cache-2.11-cpan-73692580452 )