From b8f25cea95317a4b2a622e2799f1aa7ba159bdca Mon Sep 17 00:00:00 2001 From: "Strech (Sergey Fedorov)" Date: Tue, 22 Dec 2015 23:02:26 +0100 Subject: Add mirror option for git cloning Example: vcsrepo { '/path/to/repo': ensure => mirror, provider => git, source => 'git://example.com/repo.git', } --- lib/puppet/provider/vcsrepo/git.rb | 21 ++++++++++++++++----- lib/puppet/type/vcsrepo.rb | 10 +++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 0249a3c..63986ab 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -10,10 +10,14 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes, :user, :depth, :branch, :submodules def create - if @resource.value(:revision) and @resource.value(:ensure) == :bare + if @resource.value(:revision) and ensure_bare_or_mirror? fail("Cannot set a revision (#{@resource.value(:revision)}) on a bare repository") end if !@resource.value(:source) + if @resource.value(:ensure) == :mirror + fail("Cannot init repository with mirror option, try bare instead") + end + init_repository(@resource.value(:path)) else clone_repository(default_url, @resource.value(:path)) @@ -22,7 +26,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) if @resource.value(:revision) checkout end - if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true + if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true update_submodules end @@ -85,7 +89,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) end end #TODO Would this ever reach here if it is bare? - if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true + if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true update_submodules end update_owner_and_excludes @@ -95,6 +99,10 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) bare_git_config_exists? && !working_copy_exists? end + def ensure_bare_or_mirror? + [:bare, :mirror].include? @resource.value(:ensure) + end + # If :source is set to a hash (for supporting multiple remotes), # we search for the URL for :remote. If it doesn't exist, # we throw an error. If :source is just a string, we use that @@ -197,9 +205,12 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) if @resource.value(:branch) args.push('--branch', @resource.value(:branch).to_s) end - if @resource.value(:ensure) == :bare - args << '--bare' + + case @resource.value(:ensure) + when :bare then args << '--bare' + when :mirror then args << '--mirror' end + if @resource.value(:remote) != 'origin' args.push('--origin', @resource.value(:remote)) end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb index 290bdad..e2ef0b7 100644 --- a/lib/puppet/type/vcsrepo.rb +++ b/lib/puppet/type/vcsrepo.rb @@ -69,6 +69,8 @@ Puppet::Type.newtype(:vcsrepo) do end when :bare return is == :bare + when :mirror + return is == :mirror end end @@ -83,6 +85,12 @@ Puppet::Type.newtype(:vcsrepo) do end end + newvalue :mirror, :required_features => [:bare_repositories] do + if !provider.exists? + provider.create + end + end + newvalue :absent do provider.destroy end @@ -227,7 +235,7 @@ Puppet::Type.newtype(:vcsrepo) do newparam :conflict do desc "The action to take if conflicts exist between repository and working copy" end - + newparam :trust_server_cert do desc "Trust server certificate" newvalues(:true, :false) -- cgit v1.2.3