[libcode-tidyall-perl] 175/374: typo
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:26:13 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit 426b106a9288fe37e4dd7eb85d77794934c7c240
Author: Jonathan Swartz <swartz at pobox.com>
Date: Tue Sep 4 21:44:20 2012 -0700
typo
---
bin/tidyall | 2 +-
lib/Code/TidyAll/Git/Prereceive.pm | 70 +++++++++++++++++++-------------
lib/Code/TidyAll/t/Git.pm | 79 ++++++++++++++++++++++++++++++------
3 files changed, 108 insertions(+), 43 deletions(-)
diff --git a/bin/tidyall b/bin/tidyall
index ea84a3d..e4d538e 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -488,7 +488,7 @@ according to C<tidyall>, and rejects the commit if not.
L<Code::TidyAll::Git::Precommit|Code::TidyAll::Git::Precommit> and
L<Code::TidyAll::Git::Prereceive|Code::TidyAll::Git::Prereceive> implement git
-precommit and pre-receive hooks, respectively, that check if all files are
+pre-commit and pre-receive hooks, respectively, that check if all files are
tidied and valid according to C<tidyall>.
=item *
diff --git a/lib/Code/TidyAll/Git/Prereceive.pm b/lib/Code/TidyAll/Git/Prereceive.pm
index ccd96c4..4ae4c45 100644
--- a/lib/Code/TidyAll/Git/Prereceive.pm
+++ b/lib/Code/TidyAll/Git/Prereceive.pm
@@ -1,7 +1,6 @@
package Code::TidyAll::Git::Prereceive;
use Code::TidyAll;
-use Code::TidyAll::Util qw(realpath);
-use Log::Any qw($log);
+use Code::TidyAll::Util qw(realpath tempdir_simple write_file);
use IPC::System::Simple qw(capturex run);
use Moo;
use SVN::Look;
@@ -25,28 +24,17 @@ sub check {
my $root_dir = realpath();
local $ENV{GIT_DIR} = $root_dir;
- my $conf_file = join( "/", $root_dir, $self->conf_file );
- die "could not find conf file '$conf_file'" unless -f $conf_file;
-
- my $tidyall = $self->tidyall_class->new_from_conf_file(
- $conf_file,
- no_cache => 1,
- check_only => 1,
- mode => 'commit',
- %{ $self->tidyall_options },
- );
-
- $log->info("----------------------------");
-
- my @results;
+ my ( @results, $conf_file, $tidyall );
while ( my $line = <> ) {
chomp($line);
my ( $base, $commit, $ref ) = split( /\s+/, $line );
next unless $ref eq 'refs/heads/master';
+ # Create tidyall using configuration found in first commit
+ #
+ $tidyall ||= $self->create_tidyall($commit);
+
my @files = $self->get_changed_files( $base, $commit );
- $log->infof( "base='%s', commit='%s', files=[%s]", $base, $commit,
- join( " ", @files ) );
foreach my $file (@files) {
my $contents = $self->get_file_contents( $file, $commit );
push( @results, $tidyall->process_source( $contents, $file ) );
@@ -55,24 +43,42 @@ sub check {
if ( my @error_results = grep { $_->error } @results ) {
my $error_count = scalar(@error_results);
- $fail_msg = join(
- "\n",
- sprintf(
- "%d file%s did not pass tidyall check",
- $error_count, $error_count > 1 ? "s" : ""
- ),
- map { join( ": ", $_->path, $_->msg ) } @error_results
- );
+ $fail_msg = sprintf( "%d file%s did not pass tidyall check",
+ $error_count, $error_count > 1 ? "s" : "" );
}
}
catch {
my $error = $_;
- $log->error($error);
- die $error if $params{reject_on_error};
+ if ( $params{reject_on_error} ) {
+ die $error;
+ }
+ else {
+ print STDERR "*** Error running pre-receive hook (allowing push to proceed):\n$error";
+ }
};
die $fail_msg if $fail_msg;
}
+sub create_tidyall {
+ my ( $self, $commit ) = @_;
+
+ my $temp_dir = tempdir_simple();
+ my $conf_contents = $self->get_file_contents( $self->conf_file, $commit )
+ or die sprintf( "could not find conf file '%s' in repo root", $self->conf_file );
+ my $conf_file = "$temp_dir/tidyall.ini";
+ write_file( $conf_file, $conf_contents );
+ my $tidyall = $self->tidyall_class->new_from_conf_file(
+ $conf_file,
+ mode => 'commit',
+ quiet => 1,
+ %{ $self->tidyall_options },
+ no_cache => 1,
+ no_backups => 1,
+ check_only => 1,
+ );
+ return $tidyall;
+}
+
sub get_changed_files {
my ( $self, $base, $commit ) = @_;
my $output = capturex( $self->git_path, "diff", "--numstat", "--name-only", "$base..$commit" );
@@ -162,7 +168,13 @@ Subclass to use instead of L<Code::TidyAll|Code::TidyAll>
=item tidyall_options
-Hashref of options to pass to the L<Code::TidyAll|Code::TidyAll> constructor
+Hashref of options to pass to the L<Code::TidyAll|Code::TidyAll> constructor.
+You can use this to override the default options
+
+ mode => 'commit',
+ quiet => 1,
+
+or pass additional options.
=back
diff --git a/lib/Code/TidyAll/t/Git.pm b/lib/Code/TidyAll/t/Git.pm
index 7ff598d..db44392 100644
--- a/lib/Code/TidyAll/t/Git.pm
+++ b/lib/Code/TidyAll/t/Git.pm
@@ -3,10 +3,10 @@ use Capture::Tiny qw(capture_stdout capture_stderr capture);
use Code::TidyAll::Git::Util qw(git_uncommitted_files);
use Code::TidyAll::Util qw(dirname mkpath pushd read_file realpath tempdir_simple write_file);
use Code::TidyAll;
-use IPC::System::Simple qw(run);
+use IPC::System::Simple qw(capturex run);
use Test::Class::Most parent => 'Code::TidyAll::Test::Class';
-my ( $precommit_hook_template, $tidyall_ini_template );
+my ( $precommit_hook_template, $prereceive_hook_template, $tidyall_ini_template );
sub test_git : Tests {
my ($self) = @_;
@@ -14,16 +14,20 @@ sub test_git : Tests {
my $temp_dir = tempdir_simple;
my $work_dir = "$temp_dir/work";
my $hooks_dir = "$work_dir/.git/hooks";
- my ( $stdout, $stderr );
+ my $output;
my $committed = sub {
- $stdout = capture_stdout { system('git status') };
- like( $stdout, qr/nothing to commit/, "committed" );
+ like( capturex( 'git', 'status' ), qr/nothing to commit/, "committed" );
};
-
my $uncommitted = sub {
- $stdout = capture_stdout { system('git status') };
- unlike( $stdout, qr/nothing to commit/, "uncommitted" );
+ unlike( capturex( 'git', 'status' ), qr/nothing to commit/, "committed" );
+ };
+
+ my $pushed = sub {
+ unlike( capturex( 'git', 'status' ), qr/Your branch is ahead/, "pushed" );
+ };
+ my $unpushed = sub {
+ like( capturex( 'git', 'status' ), qr/Your branch is ahead/, "unpushed" );
};
# Create the repo
@@ -59,17 +63,57 @@ sub test_git : Tests {
# Try to commit, make sure we get error
#
- $stderr = capture_stderr { system( "git", "commit", "-m", "changed", "-a" ) };
- like( $stderr, qr/1 file did not pass tidyall check/ );
- like( $stderr, qr/needs tidying/ );
+ $output = capture_stderr { system( "git", "commit", "-m", "changed", "-a" ) };
+ like( $output, qr/1 file did not pass tidyall check/, "1 file did not pass tidyall check" );
+ like( $output, qr/needs tidying/, "needs tidying" );
$uncommitted->();
# Fix file and commit successfully
#
write_file( "$work_dir/foo.txt", "ABC" );
- $stderr = capture_stderr { system( "git", "commit", "-m", "changed", "-a" ) };
- like( $stderr, qr/\[checked\] foo\.txt/ );
+ $output = capture_stderr { run( "git", "commit", "-m", "changed", "-a" ) };
+ like( $output, qr/\[checked\] foo\.txt/, "checked foo.txt" );
+ $committed->();
+
+ # Create a bare shared repo, then a clone of that
+ #
+ my $shared_dir = "$temp_dir/shared";
+ my $clone_dir = "$temp_dir/clone";
+ run( "git", "clone", "--bare", $work_dir, $shared_dir );
+ run( "git", "clone", $shared_dir, $clone_dir );
+ chdir($clone_dir);
+ $committed->();
+
+ # Add prereceive hook to shared repo
+ #
+ my $prereceive_hook_file = "$shared_dir/hooks/pre-receive";
+ my $prereceive_hook = sprintf( $prereceive_hook_template, realpath("lib") );
+ write_file( $prereceive_hook_file, $prereceive_hook );
+ chmod( 0775, $prereceive_hook_file );
+
+ # Unfix file and commit
+ #
+ write_file( "$clone_dir/foo.txt", "def" );
+ run( "git", "commit", "-m", "changed", "-a" );
+ $committed->();
+
+ # Try to push, make sure we get error back
+ #
+ $unpushed->();
+ $output = capture_stderr { system( "git", "push" ) };
+ like( $output, qr/master -> master/, "master -> master" );
+ like( $output, qr/1 file did not pass tidyall check/, "1 file did not pass tidyall check" );
+ like( $output, qr/needs tidying/, "needs tidying" );
+ $unpushed->();
+
+ # Fix file and push successfully
+ #
+ write_file( "$clone_dir/foo.txt", "DEF" );
+ $output = capture_stderr { run( "git", "commit", "-m", "changed", "-a" ) };
$committed->();
+ $output = capture_stderr { system( "git", "push" ) };
+ like( $output, qr/master -> master/, "master -> master" );
+ $pushed->();
}
$precommit_hook_template = '#!/usr/bin/perl
@@ -83,6 +127,15 @@ Code::TidyAll::Git::Precommit->check(
);
';
+$prereceive_hook_template = '#!/usr/bin/perl
+use lib qw(%s);
+use Code::TidyAll::Git::Prereceive;
+use strict;
+use warnings;
+
+Code::TidyAll::Git::Prereceive->check();
+';
+
$tidyall_ini_template = '
[+Code::TidyAll::Test::Plugin::UpperText]
select = **/*.txt
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list