From 18e88a7ec81d7f7a7bc1fd09be1e35fdc9611b4f Mon Sep 17 00:00:00 2001 From: Hyungsuk Hong Date: Mon, 10 Sep 2012 23:07:01 +0900 Subject: [PATCH 1/4] use `$HOME/.tidyall.ini` if not found `tidyall.ini` in working directories. closes [#4] --- bin/tidyall | 1 + lib/Code/TidyAll.pm | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/tidyall b/bin/tidyall index ac550a5e..e6f45a53 100755 --- a/bin/tidyall +++ b/bin/tidyall @@ -54,6 +54,7 @@ if ( ( $all_files || $svn_files || $git_files ) ) { die "cannot use filename(s) with -a/--all, -s/--svn, or -g/--git" if @ARGV; $conf_file ||= $tidyall_class->find_conf_file( cwd() ); + $params{root_dir} = cwd() if $conf_file eq "$ENV{HOME}/.tidyall.ini" my $ct = $tidyall_class->new_from_conf_file( $conf_file, %params ); my @files; diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm index f7dd5ce6..ac71d55d 100644 --- a/lib/Code/TidyAll.pm +++ b/lib/Code/TidyAll.pm @@ -320,7 +320,8 @@ sub find_conf_file { my $path1 = rel2abs($start_dir); my $path2 = realpath($start_dir); my $conf_file = $class->_find_conf_file_upward($path1) - || $class->_find_conf_file_upward($path2); + || $class->_find_conf_file_upward($path2) + || "$ENV{HOME}/.tidyall.ini"; unless ( defined $conf_file ) { die sprintf( "could not find $ini_name upwards from %s", ( $path1 eq $path2 ) ? "'$path1'" : "'$path1' or '$path2'" ); From eba6622d1752f70bf8375d0551bc03383ae0d6a0 Mon Sep 17 00:00:00 2001 From: Hyungsuk Hong Date: Tue, 11 Sep 2012 13:41:27 +0900 Subject: [PATCH 2/4] oops missing `;` --- bin/tidyall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tidyall b/bin/tidyall index e6f45a53..a39de0cc 100755 --- a/bin/tidyall +++ b/bin/tidyall @@ -54,7 +54,7 @@ if ( ( $all_files || $svn_files || $git_files ) ) { die "cannot use filename(s) with -a/--all, -s/--svn, or -g/--git" if @ARGV; $conf_file ||= $tidyall_class->find_conf_file( cwd() ); - $params{root_dir} = cwd() if $conf_file eq "$ENV{HOME}/.tidyall.ini" + $params{root_dir} = cwd() if $conf_file eq "$ENV{HOME}/.tidyall.ini"; my $ct = $tidyall_class->new_from_conf_file( $conf_file, %params ); my @files; From a6c1e5169c1ac4647a59da5d313e40beff29b7bd Mon Sep 17 00:00:00 2001 From: Hyungsuk Hong Date: Tue, 11 Sep 2012 13:42:33 +0900 Subject: [PATCH 3/4] support `$HOME/.tidyall.ini` for git pre-commit hook --- lib/Code/TidyAll/Git/Precommit.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Code/TidyAll/Git/Precommit.pm b/lib/Code/TidyAll/Git/Precommit.pm index 0e5a459d..65f32e91 100644 --- a/lib/Code/TidyAll/Git/Precommit.pm +++ b/lib/Code/TidyAll/Git/Precommit.pm @@ -30,7 +30,14 @@ sub check { 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 $global_conf_file = "$ENV{HOME}/.tidyall.ini"; + unless (-f $conf_file) { + unless (-f $global_conf_file) { + die "could not find conf file '$conf_file', '$global_conf_file'" + } else { + $conf_file = $global_conf_file; + } + } # Store the stash, and restore it upon exiting this scope unless ( $self->no_stash ) { From b51c6c9f2635e22c8f99e3030d8866f591cf3502 Mon Sep 17 00:00:00 2001 From: Hyungsuk Hong Date: Tue, 11 Sep 2012 13:45:25 +0900 Subject: [PATCH 4/4] tidy Code::TidyAll::Git::Precommit --- lib/Code/TidyAll/Git/Precommit.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Code/TidyAll/Git/Precommit.pm b/lib/Code/TidyAll/Git/Precommit.pm index 65f32e91..4facdf6e 100644 --- a/lib/Code/TidyAll/Git/Precommit.pm +++ b/lib/Code/TidyAll/Git/Precommit.pm @@ -31,10 +31,11 @@ sub check { chomp($root_dir); my $conf_file = join( "/", $root_dir, $self->conf_file ); my $global_conf_file = "$ENV{HOME}/.tidyall.ini"; - unless (-f $conf_file) { - unless (-f $global_conf_file) { - die "could not find conf file '$conf_file', '$global_conf_file'" - } else { + unless ( -f $conf_file ) { + unless ( -f $global_conf_file ) { + die "could not find conf file '$conf_file', '$global_conf_file'"; + } + else { $conf_file = $global_conf_file; } }