3 Git::RepoRoot - A factory class representing a root directory
4 containing Git repositories.
8 Git::RepoRoot is a factory class to create L<Git::Repo> instances that
9 are located under a common root directory. It also allows for
10 specifying options that all Git::Repo instances will be created with.
12 Using Git::RepoRoot to create Git::Repo instances is entirely
13 optional, but can be more convenient than instantiating them directly.
22 package Git
::RepoRoot
;
28 use base
qw(Exporter);
31 our @EXPORT_OK = qw();
37 =item $repo_root = Git::RepoRoot->new(%opts)
39 Return a new Git::RepoRoot object. The following options are
46 The directory holding all repositories.
50 All other options will be passed through to Git::Repo->new.
54 $repo_root = Git::RepoRoot->new(root_dir => '/pub/git',
55 git_binary => '/usr/bin/git');
61 Git
::Repo
::_assert_opts
(@_);
64 die 'no root_dir given' unless $self->{root_dir
};
68 =item $repo_root->repo(%opts)
70 Return a new L<Git::Repo> object. The following options are
77 The path of the repository relative to the repository root.
81 The Repo class to instantiate (default: 'Git::Repo').
85 All other options are passed through to Git::Repo.
91 Git
::Repo
::_assert_opts
(@_);
92 my %opts = (%$self, @_);
93 die 'no repo_dir given' unless $opts{repo_dir
};
94 # not technically necessary, but to guard against errors in the caller:
95 die "you passed an absolute path ($opts{repo_dir})"
96 if $opts{repo_dir
} =~ m!^/!;
97 my $repo_class = delete $opts{repo_class
} || 'Git::Repo';
98 $opts{repo_dir
} = File
::Spec
->catfile($self->{root_dir
}, $opts{repo_dir
});
99 return $repo_class->new(%opts);