Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Dieter Pearcey committed Jun 5, 2008
0 parents commit 822afa5
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -0,0 +1,11 @@
blib*
Makefile
Makefile.old
Build
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
.releaserc
Git-Wrapper-*
cover_db
4 changes: 4 additions & 0 deletions Changes
@@ -0,0 +1,4 @@
Revision history for Git-Wrapper

0.001 Date/time
First version, released on an unsuspecting world.
14 changes: 14 additions & 0 deletions MANIFEST.SKIP
@@ -0,0 +1,14 @@
MANIFEST.SKIP
^\.gitignore$
^\.git/
/\.svn/
^\.svn/
~$
\.sw.$
\.bak$
\bblib\b
\bpm_to_blib\b
^Makefile$
^Makefile\.old$
^control/
^Git-Wrapper-\d
11 changes: 11 additions & 0 deletions Makefile.PL
@@ -0,0 +1,11 @@
use inc::Module::Install;

name 'Git-Wrapper';
all_from 'lib/Git/Wrapper.pm';
author 'Hans Dieter Pearcey <hdp@cpan.org>';

build_requires 'Test::More';

auto_manifest;

WriteAll;
20 changes: 20 additions & 0 deletions README
@@ -0,0 +1,20 @@
Git-Wrapper 0.001

INSTALLATION

To install this module, run the following commands:

perl Makefile.PL
make
make test
make install

COPYRIGHT AND LICENCE

Put the correct copyright and licence information here.

Copyright (C) 2008 Hans Dieter Pearcey

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

120 changes: 120 additions & 0 deletions lib/Git/Wrapper.pm
@@ -0,0 +1,120 @@
use strict;
use warnings;

package Git::Wrapper;

our $VERSION = '0.001';

sub new {
my ($class, $arg) = @_;
my $self = bless $arg => $class;
die "usage: $class->new({ dir => '/path/to/directory' })" unless $self->dir;
return $self;
}

sub dir { shift->{dir} }

use File::pushd;

my $GIT = 'git';

sub _opt {
my $name = shift;
return length($name) == 1
? "-$name"
: "--$name"
;
}

sub AUTOLOAD {
my $self = shift;
(my $meth = our $AUTOLOAD) =~ s/.+:://;
return if $meth eq 'DESTROY';
$meth =~ tr/_/-/;

my $opt = ref $_[0] eq 'HASH' ? shift : {};

my @cmd = $GIT;

for (grep { /^-/ } keys %$opt) {
(my $name = $_) =~ s/^-//;
my $val = delete $opt->{$_};
next if $val eq '0';
push @cmd, _opt($name) . ($val eq '1' ? "" : "=$val");
}
push @cmd, $meth;
for my $name (keys %$opt) {
my $val = delete $opt->{$name};
next if $val eq '0';
push @cmd, _opt($name) . ($val eq '1' ? "" : "=$val");
}
push @cmd, @_;

#print "running [@cmd]\n";
my @out = do {
my $d = pushd $self->dir;
readpipe(join " ", map { "\Q$_\E" } @cmd);
};
#print "status: $?\n";
exit $? if $?;
chomp(@out);
return @out;
}

1;
__END__
=head1 NAME
Git::Wrapper - wrap git(7) command-line interface
=head1 VERSION
Version 0.001
=head1 SYNOPSIS
my $git = Git::Wrapper->new({ dir => "/var/foo" });
$git->commit(...)
$git->log
=head1 METHODS
Except as documented, every git subcommand is available as a method on a
Git::Wrapper object.
The first argument should be a hashref containing options and their values.
Boolean options are either true (included) or false (excluded). The remaining
arguments are passed as ordinary command arguments.
$git->commit({ all => 1, message => "stuff" });
$git->checkout("mybranch");
Output is available as an array of lines, each chomped.
@sha1s_and_titles = $git->rev_list({ all => 1, pretty => 'oneline' });
This is intentionally minimal; I don't know yet what kind of post-processing
will be useful. Expect this to change in future releases.
=head1 AUTHOR
Hans Dieter Pearcey, C<< <hdp@cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to
C<bug-git-wrapper@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>. I will be notified, and then you'll automatically be
notified of progress on your bug as I make changes.
=head1 COPYRIGHT & LICENSE
Copyright 2008 Hans Dieter Pearcey, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
7 changes: 7 additions & 0 deletions t/00-load.t
@@ -0,0 +1,7 @@
use Test::More tests => 1;

BEGIN {
use_ok('Git::Wrapper');
}

diag( "Testing Git::Wrapper $Git::Wrapper::VERSION" );
39 changes: 39 additions & 0 deletions t/basic.t
@@ -0,0 +1,39 @@
use strict;
use warnings;
use Test::More 'no_plan';

use File::Temp qw(tempdir);
use IO::File;
use Git::Wrapper;
use File::Spec;
use File::Path qw(mkpath);

my $dir = tempdir(CLEANUP => 1);

my $git = Git::Wrapper->new({ dir => $dir });

$git->init;

mkpath(File::Spec->catfile($dir, 'foo'));

IO::File->new(">" . File::Spec->catfile($dir, qw(foo bar)))->print("hello\n");

is_deeply(
[ $git->ls_files({ o => 1 }) ],
[ 'foo/bar' ],
);

$git->add('.');
is_deeply(
[ $git->ls_files ],
[ 'foo/bar' ],
);

$git->commit({ message => "FIRST" });

my @rev_list =
$git->rev_list({ all => 1, quiet => 1, pretty => 'oneline' });
is(@rev_list, 1);
like($rev_list[0], qr/^[a-f\d]{40} FIRST$/);


5 changes: 5 additions & 0 deletions t/pod-coverage.t
@@ -0,0 +1,5 @@
use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage"
if $@;
all_pod_coverage_ok();
4 changes: 4 additions & 0 deletions t/pod.t
@@ -0,0 +1,4 @@
use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
all_pod_files_ok();

0 comments on commit 822afa5

Please sign in to comment.