[libcode-tidyall-perl] 126/374: implement --svn

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:02 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 b9f0441a31a7ff5d52bbb7adda8de1473fbf4e07
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Sun Aug 5 21:02:42 2012 -0700

    implement --svn
---
 bin/tidyall                  |   25 ++++++++++++++++++++++---
 lib/Code/TidyAll.pm          |    4 ++--
 lib/Code/TidyAll/SVN/Util.pm |   20 ++++++++++++++++++++
 lib/Code/TidyAll/t/SVN.pm    |   21 ++++++++++++++-------
 4 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/bin/tidyall b/bin/tidyall
index edd5f08..31ec358 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -49,12 +49,23 @@ $conf_file = "$params{root_dir}/tidyall.ini" if $params{root_dir};
 my $tidyall_class = $params{tidyall_class} || 'Code::TidyAll';
 
 my @results;
-if ($all_files || $svn_files || $git_files) {
+if ( $all_files || $svn_files || $git_files ) {
     my $conf_file = $tidyall_class->find_conf_file( cwd() );
     my $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
-    my @files = ($all_files) ? $ct->matched_files : ($svn_files) ? Code::TidyAll::SVN->uncommitted_files() : ($git_files) ? Code::TidyAll::Git->uncommitted_files() : die;
+    my @files;
+    if ($all_files) {
+        @files = $ct->find_matched_files;
+    }
+    elsif ($svn_files) {
+        require Code::TidyAll::SVN::Util;
+        @files = Code::TidyAll::SVN::Util::svn_uncommitted_files();
+    }
+    elsif ($git_files) {
+        require Code::TidyAll::Git::Util;
+        @files = Code::TidyAll::Git::Util::git_uncommitted_files();
+    }
 }
-elsif (my @files = @ARGV) {
+elsif ( my @files = @ARGV ) {
     my $conf_file = $tidyall_class->find_conf_file( dirname( $files[0] ) );
     my $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
     @results = $ct->process_files(@files);
@@ -278,6 +289,10 @@ Process all files. Does a recursive search for all files in the project
 hierarchy, starting at the root, and processes any file that matches at least
 one plugin in the configuration.
 
+=item -g, --git
+
+Process all added or modified files in the current svn working directory.
+
 =item -h, --help       
 
 Print help message
@@ -287,6 +302,10 @@ Print help message
 Optional mode that can affect which plugins run. Defaults to 'cli'. See
 L</MODES>.
 
+=item -s, --svn
+
+Process all added or modified files in the current svn working directory.
+
 =item -q, --quiet      
 
 Suppress output except for errors.
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index 092dcc8..934abce 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -163,7 +163,7 @@ sub _plugin_conf_matches_mode {
 sub process_all {
     my $self = shift;
 
-    return $self->process_files( $self->_find_matched_files );
+    return $self->process_files( $self->find_matched_files );
 }
 
 sub process_files {
@@ -346,7 +346,7 @@ sub _find_conf_file_upward {
     }
 }
 
-sub _find_matched_files {
+sub find_matched_files {
     my ($self) = @_;
 
     my @matched_files;
diff --git a/lib/Code/TidyAll/SVN/Util.pm b/lib/Code/TidyAll/SVN/Util.pm
new file mode 100644
index 0000000..4b60db7
--- /dev/null
+++ b/lib/Code/TidyAll/SVN/Util.pm
@@ -0,0 +1,20 @@
+package Code::TidyAll::SVN::Util;
+use Cwd qw(realpath);
+use IPC::System::Simple qw(capturex);
+use strict;
+use warnings;
+use base qw(Exporter);
+
+our @EXPORT_OK = qw(svn_uncommitted_files);
+
+sub svn_uncommitted_files {
+    my ($dir) = @_;
+
+    $dir = realpath($dir);
+    my $output = capturex("svn", "status", $dir);
+    my @lines = grep { /^[AM]/ } split("\n", $output);
+    my (@files) = ($output =~ m{^[AM]\s+(.*)$}gm);
+    return @files;
+}
+
+1;
diff --git a/lib/Code/TidyAll/t/SVN.pm b/lib/Code/TidyAll/t/SVN.pm
index 606ee39..e601c35 100644
--- a/lib/Code/TidyAll/t/SVN.pm
+++ b/lib/Code/TidyAll/t/SVN.pm
@@ -1,17 +1,15 @@
 package Code::TidyAll::t::SVN;
+use Capture::Tiny qw(capture_stdout capture_stderr capture);
+use Code::TidyAll::SVN::Precommit;
+use Code::TidyAll::SVN::Util qw(svn_uncommitted_files);
 use Code::TidyAll::Util qw(dirname mkpath read_file realpath tempdir_simple write_file);
 use Code::TidyAll;
-use Capture::Tiny qw(capture_stdout capture_stderr capture);
 use IPC::System::Simple qw(run);
 use Test::Class::Most parent => 'Code::TidyAll::Test::Class';
 
 my ( $precommit_hook_template, $tidyall_ini_template );
 
-sub test_basic : Tests {
-    ok(1);
-}
-
-sub test_svn_precommit_hook : Tests {
+sub test_svn : Tests {
     my ($self) = @_;
 
     my $temp_dir = tempdir_simple;
@@ -51,6 +49,7 @@ sub test_svn_precommit_hook : Tests {
     run( sprintf( 'svn -q checkout file://%s/myapp/trunk %s',           $repo_dir, $work_dir ) );
 
     is( read_file("$work_dir/foo.txt"), "abc", "checkout and import ok" );
+    cmp_deeply( [ svn_uncommitted_files($work_dir) ], [], "no uncommitted files" );
 
     my $precommit_hook_file = "$hooks_dir/pre-commit";
     my $precommit_hook = sprintf( $precommit_hook_template, realpath("lib"), $hook_log );
@@ -58,15 +57,23 @@ sub test_svn_precommit_hook : Tests {
     chmod( 0775, $precommit_hook_file );
 
     write_file( "$work_dir/foo.txt", "abc " );
+    cmp_deeply( [ svn_uncommitted_files($work_dir) ], [ re("foo.txt") ], "one uncommitted file" );
+
     $stderr =
       capture_stderr { run( sprintf( 'svn -q commit -m "changed" %s/foo.txt', $work_dir ) ) };
     unlike( $stderr, qr/\S/ );
     $log_contains->(qr|could not find 'tidyall.ini' upwards from 'myapp/trunk/foo.txt'|);
     $clear_log->();
     $committed->();
+    cmp_deeply( [ svn_uncommitted_files($work_dir) ], [], "no uncommitted files" );
 
     write_file( "$work_dir/tidyall.ini", sprintf($tidyall_ini_template) );
-    run( sprintf( 'svn -q add %s/tidyall.ini',               $work_dir ) );
+    run( sprintf( 'svn -q add %s/tidyall.ini', $work_dir ) );
+    cmp_deeply(
+        [ svn_uncommitted_files($work_dir) ],
+        [ re("tidyall.ini") ],
+        "one uncommitted file"
+    );
     run( sprintf( 'svn -q commit -m "added" %s/tidyall.ini', $work_dir ) );
 
     write_file( "$work_dir/foo.txt", "abc" );

-- 
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