AnyEvent-Git-Wrapper
view release on metacpan or search on metacpan
my $git = AnyEvent::Git::Wrapper->new($dir);
my $version = $git->version;
if ( versioncmp( $git->version , '1.5.0') eq -1 ) {
plan skip_all =>
"Git prior to v1.5.0 doesn't support 'config' subcmd which we need for this test."
}
$git->init; # 'git init' also added in v1.5.0 so we're safe
$git->config( 'user.name' , 'Test User' );
$git->config( 'user.email' , 'test@example.com' );
# make sure git isn't munging our content so we have consistent hashes
$git->config( 'core.autocrlf' , 'false' );
$git->config( 'core.safecrlf' , 'false' );
mkpath(File::Spec->catfile($dir, 'foo'));
IO::File->new(File::Spec->catfile($dir, qw(foo bar)), '>:raw')->print("hello\n");
is_deeply(
[ $git->ls_files({ o => 1 }) ],
[ 'foo/bar' ],
);
$git->add('.');
is_deeply(
[ $git->ls_files ],
[ 'foo/bar' ],
);
SKIP: {
skip 'testing old git without porcelain' , 1 unless $git->supports_status_porcelain;
is( $git->status->is_dirty , 1 , 'repo is dirty' );
}
my $time = time;
$git->commit({ message => "FIRST\n\n\tBODY\n" });
SKIP: {
skip 'testing old git without porcelain' , 1 unless $git->supports_status_porcelain;
is( $git->status->is_dirty , 0 , 'repo is clean' );
}
my @rev_list =
$git->rev_list({ all => 1, pretty => 'oneline' });
is(@rev_list, 1);
like($rev_list[0], qr/^[a-f\d]{40} FIRST$/);
my $args = $git->supports_log_raw_dates ? { date => 'raw' } : {};
my @log = $git->log( $args );
is(@log, 1, 'one log entry');
my $log = $log[0];
is($log->id, (split /\s/, $rev_list[0])[0], 'id');
is($log->message, "FIRST\n\n\tBODY\n", "message");
throws_ok { $git->log( "--format=%H" ) } q{Git::Wrapper::Exception};
SKIP: {
skip 'testing old git without raw date support' , 1
unless $git->supports_log_raw_dates;
my $log_date = $log->date;
$log_date =~ s/ [+-]\d+$//;
cmp_ok(( $log_date - $time ), '<=', 5, 'date');
}
SKIP:
{
skip 'testing old git without no abbrev commit support' , 1
unless $git->supports_log_no_abbrev_commit;
$git->config( 'log.abbrevCommit', 'true' );
@log = $git->log( $args );
$log = $log[0];
is($log->id, (split /\s/, $rev_list[0])[0], 'id');
}
SKIP:
{
if ( versioncmp( $git->version , '1.6.3') eq -1 ) {
skip 'testing old git without log --oneline support' , 3;
}
throws_ok { $git->log('--oneline') } qr/^unhandled/ , 'log(--oneline) dies';
my @lines;
lives_ok { @lines = $git->RUN('log' , '--oneline' ) } 'RUN(log --oneline) lives';
is( @lines , 1 , 'one log entry' );
}
my @raw_log = $git->log({ raw => 1 });
is(@raw_log, 1, 'one raw log entry');
SKIP: {
if ( $^O eq "MSWin32" ) {
skip 'testing file permissions on Windows is unreliable; see also core.filemode', 1;
}
my $raw_log = $raw_log[0];
my $excepted_mod = Git::Wrapper::File::RawModification->new(
"foo/bar","A",'000000','100644','0000000000000000000000000000000000000000','ce013625030ba8dba906f756967f9e9ca394464a'
);
is_deeply($raw_log->modifications, $excepted_mod);
}
sub _timeout (&) {
my ($code) = @_;
my $timeout = 0;
eval {
local $SIG{ALRM} = sub { $timeout = 1; die "TIMEOUT\n" };
# 5 seconds should be more than enough time to fail properly
alarm 5;
$code->();
alarm 0;
};
return $timeout;
}
my $commit_count = 1;
SKIP: {
if ( versioncmp( $git->version , '1.7.0.5') eq -1 ) {
skip 'testing old git without commit --allow-empty-message support' , 1;
}
if ( $^O eq "MSWin32" ) {
skip 'testing with timeout on Windows is unreliable', 1;
}
# Test empty commit message
IO::File->new(">" . File::Spec->catfile($dir, qw(second_commit)))->print("second_commit\n");
$git->add('second_commit');
# If this fails there's a distinct danger it will hang indefinitely
my $timeout = _timeout { $git->commit };
ok !$timeout && $@, 'Attempt to commit interactively fails quickly'
or diag "Timed out!";
$timeout = _timeout {
$git->commit({ message => "", 'allow-empty-message' => 1 });
};
if ( $@ && !$timeout ) {
( run in 0.710 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )