From 852b1688fbf5129d0e365586b6d87a59fe31ba29 Mon Sep 17 00:00:00 2001 From: Nicolas Vigier Date: Mon, 15 Jul 2013 18:18:33 +0200 Subject: In repos_config, allow giving a git_url instead of a directory path The git url will be cloned automatically (if target directory does not exist), or pulled automatically. --- lib/MGA/Git.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/MGA/Git.pm') diff --git a/lib/MGA/Git.pm b/lib/MGA/Git.pm index e051bb9..e518189 100644 --- a/lib/MGA/Git.pm +++ b/lib/MGA/Git.pm @@ -1,9 +1,11 @@ package MGA::Git; use strict; +use Git; use YAML qw(LoadFile); use Template; use File::Slurp; +use File::Basename; use Net::LDAP; use feature 'state'; use Data::Dump qw/dd/; @@ -16,6 +18,19 @@ my $etc_config = LoadFile($etc_config_file); sub load_gitrepos_dir { my ($repos, $infos) = @_; + if (!$infos->{include_dir}) { + my ($dir) = fileparse($infos->{git_url}); + $dir =~ s/\.git$//; + $infos->{include_dir} = "$config->{repodef_dir}/$dir"; + if (-d $infos->{include_dir}) { + my $repo = Git->repository(Directory => $infos->{include_dir}); + $repo->command('pull'); + } else { + Git::command('clone', $infos->{git_url}, $infos->{include_dir}); + my $repo = Git->repository(Directory => $infos->{include_dir}); + $repo->command('remote', 'add', 'origin', $infos->{git_url}); + } + } opendir(my $dh, $infos->{include_dir}) || die "Error opening $infos->{include_dir}: $!"; while (my $file = readdir($dh)) { @@ -40,7 +55,9 @@ sub load_gitrepos { my ($r) = @_; $r->{repos} = {}; foreach my $repodef (@{$config->{repos_config}}) { - load_gitrepos_dir($r->{repos}, $repodef) if $repodef->{include_dir}; + if ($repodef->{include_dir} || $repodef->{git_url}) { + load_gitrepos_dir($r->{repos}, $repodef); + } foreach my $repo ($repodef->{repos} ? @{$repodef->{repos}} : ()) { my $name = "$repodef->{prefix}/$repo->{name}"; $r->{repos}{$name} = $repo; -- cgit v1.2.1