Permalink
Browse files

rename _cmd() to RUN(); document for public use

addresses #5, maybe #7
  • Loading branch information...
1 parent 36d6f14 commit a4ef495b499f65aee4d6b6679f967e45872dc0a4 @genehack committed Feb 8, 2012
Showing with 38 additions and 6 deletions.
  1. +30 −6 lib/Git/Wrapper.pm
  2. +8 −0 t/basic.t
View
@@ -39,7 +39,7 @@ sub _opt {
;
}
-sub _cmd {
+sub RUN {
my $self = shift;
my $cmd = shift;
@@ -133,13 +133,13 @@ sub AUTOLOAD {
$meth =~ tr/_/-/;
- return $self->_cmd($meth, @_);
+ return $self->RUN($meth, @_);
}
sub version {
my $self = shift;
- my ($version) = $self->_cmd('version');
+ my ($version) = $self->RUN('version');
$version =~ s/^git version //;
@@ -153,7 +153,7 @@ sub log {
$opt->{no_color} = 1;
$opt->{pretty} = 'medium';
- my @out = $self->_cmd(log => $opt, @_);
+ my @out = $self->RUN(log => $opt, @_);
my @logs;
while (my $line = shift @out) {
@@ -211,13 +211,13 @@ my %STATUS_CONFLICTS = map { $_ => 1 } qw<DD AU UD UA DU AA UU>;
sub status {
my $self = shift;
- return $self->_cmd('status' , @_ )
+ return $self->RUN('status' , @_ )
unless $self->supports_status_porcelain;
my $opt = ref $_[0] eq 'HASH' ? shift : {};
$opt->{$_} = 1 for qw<porcelain>;
- my @out = $self->_cmd(status => $opt, @_);
+ my @out = $self->RUN(status => $opt, @_);
my $statuses = Git::Wrapper::Statuses->new;
@@ -560,6 +560,30 @@ See git-status man page for more details.
}
}
+=head2 RUN
+
+This method bypasses the output rearranging performed by some of the wrapped
+methods described above (i.e., C<log>, C<status>, etc.). This can be useful
+in various situations, such as when you want to produce a particular log
+output format that isn't compatible with the way C<Git::Wrapper> constructs
+C<Git::Wrapper::Log>, or when you want raw C<git status> output that isn't
+parsed into a <Git::Wrapper::Status> object.
+
+This method should be called with an initial string argument of the C<git>
+subcommand you want to run, followed by a hashref containing options and their
+values, and then a list of any other arguments.
+
+=head3 Example
+
+ my $git = Git::Wrapper->new( '/path/to/git/repo' );
+
+ # the 'log' method returns Git::Wrapper::Log objects
+ my @log_objects = $git->log();
+
+ # while 'RUN('log')' returns an array of chomped lines
+ my @log_lines = $git->RUN('log');
+
+
=head1 COMPATIBILITY
On Win32 Git::Wrapper is incompatible with msysGit installations earlier than
View
@@ -9,6 +9,7 @@ use File::Spec;
use File::Path qw(mkpath);
use POSIX qw(strftime);
use Test::Deep;
+use Test::Exception;
unless ( Git::Wrapper->has_git_in_path ) {
diag 'EXITING TESTS due to lack of installed git in $PATH.';
@@ -66,6 +67,7 @@ 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");
@@ -79,6 +81,12 @@ SKIP: {
cmp_ok(( $log_date - $time ), '<=', 5, 'date');
}
+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' );
+
SKIP: {
# Test empty commit message
IO::File->new(">" . File::Spec->catfile($dir, qw(second_commit)))->print("second_commit\n");

0 comments on commit a4ef495

Please sign in to comment.