diff options
author | Nicolas Vigier <boklm@mars-attacks.org> | 2013-07-15 18:18:33 +0200 |
---|---|---|
committer | Nicolas Vigier <boklm@mars-attacks.org> | 2013-07-15 18:18:33 +0200 |
commit | 852b1688fbf5129d0e365586b6d87a59fe31ba29 (patch) | |
tree | 8084da4d1af3a09cdce5d28dd8c8f8efd811d78d /lib | |
parent | 510d51e76a470039c11f9a20b8a2e4ae3dce1bb5 (diff) | |
download | mgagit-852b1688fbf5129d0e365586b6d87a59fe31ba29.tar mgagit-852b1688fbf5129d0e365586b6d87a59fe31ba29.tar.gz mgagit-852b1688fbf5129d0e365586b6d87a59fe31ba29.tar.bz2 mgagit-852b1688fbf5129d0e365586b6d87a59fe31ba29.tar.xz mgagit-852b1688fbf5129d0e365586b6d87a59fe31ba29.zip |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MGA/Git.pm | 19 |
1 files changed, 18 insertions, 1 deletions
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; |