1 package App::Rgit::Repository;
6 use Cwd qw/cwd abs_path/;
7 use File::Spec::Functions qw/catdir splitdir abs2rel/;
9 use Object::Tiny qw/fake repo bare name work/;
11 use App::Rgit::Utils qw/validate/;
15 App::Rgit::Repository - Class representing a Git repository.
23 our $VERSION = '0.02';
27 Class representing a Git repository.
29 This is an internal class to L<rgit>.
33 =head2 C<< new dir => $dir [, fake => 1 ] >>
35 Creates a new repository starting from C<$dir>.
36 If the C<fake> option is passed, C<$dir> isn't checked to be a valid C<git> repository.
41 my ($class, %args) = &validate;
43 $dir = abs_path $dir if defined $dir;
44 $dir = cwd unless defined $dir;
45 my ($repo, $bare, $name, $work);
50 push @tries, "$dir.git" unless $dir =~ /\.git$/;
51 push @tries, catdir($dir, '.git') unless $dir eq '.git';
53 if (-d $_ && -d "$_/refs" and -d "$_/objects" and -e "$_/HEAD") {
58 return unless defined $repo;
59 my @chunks = splitdir($repo);
60 my $last = pop @chunks;
61 if ($last eq '.git') {
64 $work = catdir(@chunks);
67 ($name) = $last =~ /(.*)\.git$/;
72 fake => !!$args{fake},
82 C<chdir> into the repository's directory.
88 my $dir = $self->work;
90 warn "Couldn't chdir into $dir: $!";
96 =head2 C<run $conf, @args>
98 Runs C<git @args> on the repository for the L<App::Rgit::Config> configuration C<$conf>.
99 When the repository isn't fake, the format substitutions applies to C<@args> elements.
100 Returns the exit code.
106 $a = $_[0] unless defined $a;
113 return unless $conf->isa('App::Rgit::Config');
115 unless ($self->fake) {
118 'n' => sub { $self->name },
119 'g' => sub { _abs2rel($self->repo, $conf->root) },
120 'G' => sub { $self->repo },
121 'w' => sub { _abs2rel($self->work, $conf->root) },
122 'W' => sub { $self->work },
123 'b' => sub { _abs2rel($self->bare ? $self->repo : $self->work . '.git', $conf->root) },
124 'B' => sub { $self->bare ? $self->repo : $self->work . '.git' },
125 'R' => sub { $conf->root },
127 s/\^([\^ngGwWbBR])/$escapes{$1}->()/eg for @args;
129 system { $conf->git } $conf->git, @args;
150 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
152 You can contact me by mail or on C<irc.perl.org> (vincent).
156 Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
160 You can find documentation for this module with the perldoc command.
162 perldoc App::Rgit::Repository
164 =head1 COPYRIGHT & LICENSE
166 Copyright 2008 Vincent Pit, all rights reserved.
168 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
172 1; # End of App::Rgit::Repository