[libcode-tidyall-perl] 269/374: adjust to use tidyall.ini or .tidyallrc
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:26:33 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 10c60ddc8e4380bdbdfd0e706a93440159089159
Author: Jonathan Swartz <swartz at pobox.com>
Date: Tue Sep 25 21:18:39 2012 -0700
adjust to use tidyall.ini or .tidyallrc
---
lib/Code/TidyAll/Git/Precommit.pm | 20 +++++++++++++-------
lib/Code/TidyAll/Git/Prereceive.pm | 18 +++++++++++-------
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/lib/Code/TidyAll/Git/Precommit.pm b/lib/Code/TidyAll/Git/Precommit.pm
index 0e5a459..a30233f 100644
--- a/lib/Code/TidyAll/Git/Precommit.pm
+++ b/lib/Code/TidyAll/Git/Precommit.pm
@@ -10,7 +10,7 @@ use Moo;
use Try::Tiny;
# Public
-has 'conf_file' => ( is => 'ro', default => sub { "tidyall.ini" } );
+has 'conf_name' => ( is => 'ro' );
has 'git_path' => ( is => 'ro', default => sub { 'git' } );
has 'no_stash' => ( is => 'ro' );
has 'reject_on_error' => ( is => 'ro' );
@@ -29,8 +29,10 @@ sub check {
# Find conf file at git root
my $root_dir = capturex( $self->git_path, "rev-parse", "--show-toplevel" );
chomp($root_dir);
- my $conf_file = join( "/", $root_dir, $self->conf_file );
- die "could not find conf file '$conf_file'" unless -f $conf_file;
+ my @conf_names =
+ $self->conf_name ? ( $self->conf_name ) : Code::TidyAll->default_conf_names;
+ my ($conf_file) = grep { -f } map { join( "/", $root_dir, $_ ) } @conf_names
+ or die sprintf( "could not find conf file %s", join( " or ", @conf_names ) );
# Store the stash, and restore it upon exiting this scope
unless ( $self->no_stash ) {
@@ -119,8 +121,8 @@ In an emergency the hook can be bypassed by passing --no-verify to commit:
or you can just move C<.git/hooks/pre-commit> out of the way temporarily.
-The configuration file C<tidyall.ini> must be checked into git in the repo root
-directory i.e. next to the .git directory.
+The configuration file (C<tidyall.ini> or C<.tidyallrc>) must be checked into
+git in the repo root directory i.e. next to the .git directory.
The hook will stash any changes not in the index beforehand, and restore them
afterwards, via
@@ -129,8 +131,8 @@ afterwards, via
....
git stash pop -q
-This means that if C<tidyall.ini> has uncommitted changes that are not in the
-index, they will not affect the tidyall run.
+This means that if the configuration file has uncommitted changes that are not
+in the index, they will not affect the tidyall run.
Passes mode = "commit" by default; see L<modes|tidyall/MODES>.
@@ -138,6 +140,10 @@ Key/value parameters:
=over
+=item conf_name
+
+Conf file name to search for instead of the defaults.
+
=item git_path
Path to git to use in commands, e.g. '/usr/bin/git' or '/usr/local/bin/git'. By
diff --git a/lib/Code/TidyAll/Git/Prereceive.pm b/lib/Code/TidyAll/Git/Prereceive.pm
index dcb3749..8ef4dc5 100644
--- a/lib/Code/TidyAll/Git/Prereceive.pm
+++ b/lib/Code/TidyAll/Git/Prereceive.pm
@@ -1,12 +1,13 @@
package Code::TidyAll::Git::Prereceive;
use Code::TidyAll;
use Code::TidyAll::Util qw(realpath tempdir_simple write_file);
+use Capture::Tiny qw(capture);
use IPC::System::Simple qw(capturex run);
use Moo;
use Try::Tiny;
# Public
-has 'conf_file' => ( is => 'ro', default => sub { "tidyall.ini" } );
+has 'conf_name' => ( is => 'ro' );
has 'extra_conf_files' => ( is => 'ro', default => sub { [] } );
has 'git_path' => ( is => 'ro', default => sub { 'git' } );
has 'reject_on_error' => ( is => 'ro' );
@@ -24,7 +25,7 @@ sub check {
my $root_dir = realpath();
local $ENV{GIT_DIR} = $root_dir;
- my ( @results, $conf_file, $tidyall );
+ my ( @results, $tidyall );
while ( my $line = <> ) {
chomp($line);
my ( $base, $commit, $ref ) = split( /\s+/, $line );
@@ -63,13 +64,16 @@ sub create_tidyall {
my ( $self, $commit ) = @_;
my $temp_dir = tempdir_simple();
- foreach my $rel_file ( $self->conf_file, @{ $self->extra_conf_files } ) {
+ my @conf_names = $self->conf_name ? ( $self->conf_name ) : Code::TidyAll->default_conf_names;
+ my ($conf_file) = grep { $self->get_file_contents( $_, $commit ) } @conf_names
+ or die sprintf( "could not find conf file %s", join( " or ", @conf_names ) );
+ foreach my $rel_file ( $conf_file, @{ $self->extra_conf_files } ) {
my $contents = $self->get_file_contents( $rel_file, $commit )
or die sprintf( "could not find file '%s' in repo root", $rel_file );
write_file( "$temp_dir/$rel_file", $contents );
}
my $tidyall = $self->tidyall_class->new_from_conf_file(
- "$temp_dir/" . $self->conf_file,
+ "$temp_dir/" . $conf_file,
mode => 'commit',
quiet => 1,
%{ $self->tidyall_options },
@@ -89,7 +93,7 @@ sub get_changed_files {
sub get_file_contents {
my ( $self, $file, $commit ) = @_;
- my $contents = capturex( $self->git_path, "show", "$commit:$file" );
+ my ( $contents, $error ) = capture { system( $self->git_path, "show", "$commit:$file" ) };
return $contents;
}
@@ -148,8 +152,8 @@ is rejected and the reason(s) are output to the client. e.g.
To ...
! [remote rejected] master -> master (pre-receive hook declined)
-The configuration file C<tidyall.ini> must be checked into git in the repo root
-directory, i.e. next to the .git directory.
+The configuration file (C<tidyall.ini> or C<.tidyallrc>) must be checked into
+git in the repo root directory, i.e. next to the .git directory.
Unfortunately there is no easy way to bypass the pre-receive hook in an
emergency. It must be disabled in the repo being pushed to, e.g. by renaming
--
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