Code-TidyAll
view release on metacpan or search on metacpan
lib/Code/TidyAll/Git/Precommit.pm view on Meta::CPAN
use warnings;
use Code::TidyAll::Git::Precommit;
Code::TidyAll::Git::Precommit->check();
=item *
Add a setup script in F<git/setup.sh> containing
#!/bin/bash
chmod +x git/hooks/pre-commit
cd .git/hooks
ln -s ../../git/hooks/pre-commit
=item *
Run C<git/setup.sh> (or tell your developers to run it) once for each new clone
of the repo
=back
t/lib/TestFor/Code/TidyAll/Basic.pm view on Meta::CPAN
sub test_filemode : Tests {
my $self = shift;
if ( $^O eq 'MSWin32' || $^O eq 'msys' ) {
$self->builder->skip('File mode on Windows is weird');
return;
}
my $root_dir = $self->create_dir( { 'foo.txt' => 'abc' } );
my $file = $root_dir->child('foo.txt');
$file->chmod('0755');
my $ct = Code::TidyAll->new(
plugins => { test_plugin('UpperText') => { select => '**/foo*' } },
root_dir => $root_dir,
);
$ct->process_paths($file);
is( $file->slurp, 'ABC' );
is( $file->stat->mode, 0100755 );
}
sub test_multiple_plugin_instances : Tests {
t/lib/TestFor/Code/TidyAll/Git.pm view on Meta::CPAN
runx( qw( git clone -q --bare ), map { _quote_for_win32($_) } $work_dir, $shared_dir );
runx( qw( git clone -q ), map { _quote_for_win32($_) } $shared_dir, $clone_dir );
chdir($clone_dir);
$self->_assert_nothing_to_commit($work_dir);
};
my $prereceive_hook_file = $shared_dir->child(qw( hooks pre-receive ));
my $prereceive_hook = sprintf( $prereceive_hook_template, $self->_lib_dirs );
$prereceive_hook_file->spew($prereceive_hook);
$prereceive_hook_file->chmod(0775);
subtest 'untidy file and attempt to commit it via commit -a', sub {
$clone_dir->child('foo.txt')->spew_raw("def\n");
runx(qw( git commit -q -m changed -a ));
$self->_assert_nothing_to_commit($work_dir);
$self->_assert_branch_is_ahead_of_origin;
};
subtest 'cannot push untidy file', sub {
my $output = capture_stderr { system(qw( git push )) };
t/lib/TestFor/Code/TidyAll/Git.pm view on Meta::CPAN
my $pushd = pushd($work_dir);
$work_dir->child('tidyall.ini')->spew($tidyall_ini_template);
$work_dir->child('.gitignore')->spew('.tidyall.d');
runx(qw( git add tidyall.ini .gitignore ));
runx(qw( git commit -q -m added tidyall.ini .gitignore ));
my $precommit_hook_file = $hooks_dir->child('pre-commit');
my $precommit_hook = sprintf( $precommit_hook_template, $self->_lib_dirs );
$precommit_hook_file->spew($precommit_hook);
$precommit_hook_file->chmod(0755);
return ( $temp_dir, $work_dir, $pushd );
}
sub _quote_for_win32 {
# The docs for IPC::System::Simple lie about how it works on Windows. On
# Windows it _always_ invokes a shell, so we need to quote a path with
# spaces.
return $_[0] unless IS_WIN32 && $_[0] =~ / /;
t/lib/TestFor/Code/TidyAll/SVN.pm view on Meta::CPAN
run( sprintf( q{svn -q import %s file://%s/myapp/trunk -m "import"}, $src_dir, $repo_dir ) );
run( sprintf( 'svn -q checkout file://%s/myapp/trunk %s', $repo_dir, $work_dir ) );
my $foo_txt = $work_dir->child('foo.txt');
is( $foo_txt->slurp, 'abc', 'checkout and import ok' );
cmp_deeply( [ svn_uncommitted_files($work_dir) ], [], 'no uncommitted files' );
my $precommit_hook_file = $hooks_dir->child('pre-commit');
my $precommit_hook = sprintf( $precommit_hook_template, path('lib')->realpath, $hook_log );
$precommit_hook_file->spew($precommit_hook);
$precommit_hook_file->chmod(0755);
my $bar_dir = $work_dir->child('bar');
$bar_dir->mkpath( { mode => 0755 } );
$bar_dir->child('foo.txt')->spew('abc ');
run( sprintf( 'svn -q add %s', $bar_dir ) );
cmp_deeply( [ svn_uncommitted_files($work_dir) ], [ re('foo.txt') ], 'one uncommitted file' );
$stderr = capture_stderr {
run( sprintf( q{svn -q commit -m "changed" %s %s}, $foo_txt, $bar_dir ) );
( run in 0.477 second using v1.01-cache-2.11-cpan-496ff517765 )