Git-Wrapper
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More;
use File::Temp qw(tempdir);
use IO::File;
use Git::Wrapper;
use File::Spec;
use File::Path qw(mkpath);
use POSIX qw(strftime);
use Sort::Versions;
use Test::Deep;
use Test::Exception;
my $dir = tempdir(CLEANUP => 1);
my $git = 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."
}
diag( "Testing git version: " . $version );
$git->init; # 'git init' also added in v1.5.0 so we're safe
# see https://github.com/genehack/Git-Wrapper/issues/91
$git->config('commit.gpgsign', 'false');
$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 $commit_count = 0;
my $time = time;
$git->commit({ message => "FIRST\n\n\tBODY\n" });
$commit_count++;
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;
( run in 0.808 second using v1.01-cache-2.11-cpan-df04353d9ac )