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. --- NEWS | 2 ++ README | 7 ++++++- config_default | 1 + lib/MGA/Git.pm | 19 ++++++++++++++++++- mgagit.conf | 3 ++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 660c191..8d0f9ad 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ branches by default, unless lockdown is set to 'yes' for this repo - soft_repo.gl: set maintainer as gitweb.owner - provide access to users ldap infos from templates +- in repos_config, allow giving a git_url instead of a directory path, + to be cloned and pulled automatically Version 0.4 diff --git a/README b/README index 5d2115b..e411b41 100644 --- a/README +++ b/README @@ -39,9 +39,14 @@ The following configuration options are available : pubkey_dir: directory containing users ssh keys, used by gitolite tmpl_dir: templates directory gitolite_config: gitolite configuration file + repodef_dir: directory containing repos definitions (see repos_config) repos_config: list of repos definition directories. Use something like this to include a directory containing repos definitions : - prefix: prefix in the repos tree - include_dir: path to the directory containing definitions + git_url: url of a git repository containing definitions, that will be + cloned and pulled, in 'repodef_dir' + include_dir: alternatively, you can specify the path to a directory + containing definitions (if it's not from a git repository, + or if you don't want to be pulled automatically) gl_template: template file used to define the repos diff --git a/config_default b/config_default index 1f9dc53..d51aca8 100644 --- a/config_default +++ b/config_default @@ -12,6 +12,7 @@ group_re: '^cn=(.+),ou=Group,dc=mageia,dc=org$' pubkey_dir: /var/lib/git/.gitolite/keydir tmpl_dir: /usr/share/mgagit/tmpl gitolite_config: /var/lib/git/.gitolite/conf/gitolite.conf +repodef_dir: /var/lib/git/repos-config repos_config: - prefix: software include_dir: /var/lib/git/repos/software 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; diff --git a/mgagit.conf b/mgagit.conf index 0db3174..dbc42d5 100644 --- a/mgagit.conf +++ b/mgagit.conf @@ -2,7 +2,8 @@ use_ldap: no gitolite_config: /var/lib/git/.gitolite/conf/gitolite.conf pubkey_dir: /home/boklm/.gitolite/keydir +repodef_dir: /var/lib/git/repos-config repos_config: - prefix: software - include_dir: /var/lib/git/repodef/software + git_url: git://git.mageia.org/infrastructure/repositories/software.git gl_template: soft_repo -- cgit v1.2.1