Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first draft

  • Loading branch information...
commit 822afa5ce3ec87a6c8be4b78410c15e2d73f93e2 0 parents
authored June 04, 2008
11  .gitignore
... ...
@@ -0,0 +1,11 @@
  1
+blib*
  2
+Makefile
  3
+Makefile.old
  4
+Build
  5
+_build*
  6
+pm_to_blib*
  7
+*.tar.gz
  8
+.lwpcookies
  9
+.releaserc
  10
+Git-Wrapper-*
  11
+cover_db
4  Changes
... ...
@@ -0,0 +1,4 @@
  1
+Revision history for Git-Wrapper
  2
+
  3
+0.001   Date/time
  4
+        First version, released on an unsuspecting world.
14  MANIFEST.SKIP
... ...
@@ -0,0 +1,14 @@
  1
+MANIFEST.SKIP
  2
+^\.gitignore$
  3
+^\.git/
  4
+/\.svn/
  5
+^\.svn/
  6
+~$
  7
+\.sw.$
  8
+\.bak$
  9
+\bblib\b
  10
+\bpm_to_blib\b
  11
+^Makefile$
  12
+^Makefile\.old$
  13
+^control/
  14
+^Git-Wrapper-\d
11  Makefile.PL
... ...
@@ -0,0 +1,11 @@
  1
+use inc::Module::Install;
  2
+
  3
+name     'Git-Wrapper';
  4
+all_from 'lib/Git/Wrapper.pm';
  5
+author   'Hans Dieter Pearcey <hdp@cpan.org>';
  6
+
  7
+build_requires 'Test::More';
  8
+
  9
+auto_manifest;
  10
+
  11
+WriteAll;
20  README
... ...
@@ -0,0 +1,20 @@
  1
+Git-Wrapper 0.001
  2
+
  3
+INSTALLATION
  4
+
  5
+To install this module, run the following commands:
  6
+
  7
+	perl Makefile.PL
  8
+	make
  9
+	make test
  10
+	make install
  11
+
  12
+COPYRIGHT AND LICENCE
  13
+
  14
+Put the correct copyright and licence information here.
  15
+
  16
+Copyright (C) 2008 Hans Dieter Pearcey
  17
+
  18
+This library is free software; you can redistribute it and/or modify
  19
+it under the same terms as Perl itself.
  20
+
120  lib/Git/Wrapper.pm
... ...
@@ -0,0 +1,120 @@
  1
+use strict;
  2
+use warnings;
  3
+
  4
+package Git::Wrapper;
  5
+
  6
+our $VERSION = '0.001';
  7
+
  8
+sub new {
  9
+  my ($class, $arg) = @_;
  10
+  my $self = bless $arg => $class;
  11
+  die "usage: $class->new({ dir => '/path/to/directory' })" unless $self->dir;
  12
+  return $self;
  13
+}
  14
+
  15
+sub dir { shift->{dir} }
  16
+
  17
+use File::pushd;
  18
+
  19
+my $GIT = 'git';
  20
+
  21
+sub _opt {
  22
+  my $name = shift;
  23
+  return length($name) == 1 
  24
+    ? "-$name"
  25
+    : "--$name"
  26
+  ;
  27
+}
  28
+
  29
+sub AUTOLOAD {
  30
+  my $self = shift;
  31
+  (my $meth = our $AUTOLOAD) =~ s/.+:://;
  32
+  return if $meth eq 'DESTROY';
  33
+  $meth =~ tr/_/-/;
  34
+
  35
+  my $opt = ref $_[0] eq 'HASH' ? shift : {};
  36
+
  37
+  my @cmd = $GIT;
  38
+
  39
+  for (grep { /^-/ } keys %$opt) {
  40
+    (my $name = $_) =~ s/^-//;
  41
+    my $val = delete $opt->{$_};
  42
+    next if $val eq '0';
  43
+    push @cmd, _opt($name) . ($val eq '1' ? "" : "=$val");
  44
+  }
  45
+  push @cmd, $meth;
  46
+  for my $name (keys %$opt) {
  47
+    my $val = delete $opt->{$name};
  48
+    next if $val eq '0';
  49
+    push @cmd, _opt($name) . ($val eq '1' ? "" : "=$val");
  50
+  }
  51
+  push @cmd, @_;
  52
+    
  53
+  #print "running [@cmd]\n";
  54
+  my @out = do {
  55
+    my $d = pushd $self->dir;
  56
+    readpipe(join " ", map { "\Q$_\E" } @cmd);
  57
+  };
  58
+  #print "status: $?\n";
  59
+  exit $? if $?;
  60
+  chomp(@out);
  61
+  return @out;
  62
+}
  63
+
  64
+1;
  65
+__END__
  66
+
  67
+=head1 NAME
  68
+
  69
+Git::Wrapper - wrap git(7) command-line interface
  70
+
  71
+=head1 VERSION
  72
+
  73
+  Version 0.001
  74
+
  75
+=head1 SYNOPSIS
  76
+
  77
+  my $git = Git::Wrapper->new({ dir => "/var/foo" });
  78
+
  79
+  $git->commit(...)
  80
+  $git->log
  81
+
  82
+=head1 METHODS
  83
+
  84
+Except as documented, every git subcommand is available as a method on a
  85
+Git::Wrapper object.
  86
+
  87
+The first argument should be a hashref containing options and their values.
  88
+Boolean options are either true (included) or false (excluded).  The remaining
  89
+arguments are passed as ordinary command arguments.
  90
+
  91
+  $git->commit({ all => 1, message => "stuff" });
  92
+
  93
+  $git->checkout("mybranch");
  94
+
  95
+Output is available as an array of lines, each chomped.
  96
+
  97
+  @sha1s_and_titles = $git->rev_list({ all => 1, pretty => 'oneline' });
  98
+
  99
+This is intentionally minimal; I don't know yet what kind of post-processing
  100
+will be useful.  Expect this to change in future releases.
  101
+
  102
+=head1 AUTHOR
  103
+
  104
+Hans Dieter Pearcey, C<< <hdp@cpan.org> >>
  105
+
  106
+=head1 BUGS
  107
+
  108
+Please report any bugs or feature requests to
  109
+C<bug-git-wrapper@rt.cpan.org>, or through the web interface at
  110
+L<http://rt.cpan.org>.  I will be notified, and then you'll automatically be
  111
+notified of progress on your bug as I make changes.
  112
+
  113
+=head1 COPYRIGHT & LICENSE
  114
+
  115
+Copyright 2008 Hans Dieter Pearcey, All Rights Reserved.
  116
+
  117
+This program is free software; you can redistribute it and/or modify it
  118
+under the same terms as Perl itself.
  119
+
  120
+=cut
7  t/00-load.t
... ...
@@ -0,0 +1,7 @@
  1
+use Test::More tests => 1;
  2
+
  3
+BEGIN {
  4
+  use_ok('Git::Wrapper');
  5
+}
  6
+
  7
+diag( "Testing Git::Wrapper $Git::Wrapper::VERSION" );
39  t/basic.t
... ...
@@ -0,0 +1,39 @@
  1
+use strict;
  2
+use warnings;
  3
+use Test::More 'no_plan';
  4
+
  5
+use File::Temp qw(tempdir);
  6
+use IO::File;
  7
+use Git::Wrapper;
  8
+use File::Spec;
  9
+use File::Path qw(mkpath);
  10
+
  11
+my $dir = tempdir(CLEANUP => 1);
  12
+
  13
+my $git = Git::Wrapper->new({ dir => $dir });
  14
+
  15
+$git->init;
  16
+
  17
+mkpath(File::Spec->catfile($dir, 'foo'));
  18
+
  19
+IO::File->new(">" . File::Spec->catfile($dir, qw(foo bar)))->print("hello\n");
  20
+
  21
+is_deeply(
  22
+  [ $git->ls_files({ o => 1 }) ],
  23
+  [ 'foo/bar' ],
  24
+);
  25
+
  26
+$git->add('.');
  27
+is_deeply(
  28
+  [ $git->ls_files ],
  29
+  [ 'foo/bar' ],
  30
+);
  31
+
  32
+$git->commit({ message => "FIRST" });
  33
+
  34
+my @rev_list =  
  35
+  $git->rev_list({ all => 1, quiet => 1, pretty => 'oneline' });
  36
+is(@rev_list, 1);
  37
+like($rev_list[0], qr/^[a-f\d]{40} FIRST$/);
  38
+  
  39
+
5  t/pod-coverage.t
... ...
@@ -0,0 +1,5 @@
  1
+use Test::More;
  2
+eval "use Test::Pod::Coverage 1.04";
  3
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage"
  4
+    if $@;
  5
+all_pod_coverage_ok();
4  t/pod.t
... ...
@@ -0,0 +1,4 @@
  1
+use Test::More;
  2
+eval "use Test::Pod 1.14";
  3
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
  4
+all_pod_files_ok();

0 notes on commit 822afa5

Please sign in to comment.
Something went wrong with that request. Please try again.