diff options
author | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-05-13 17:29:28 -0400 |
---|---|---|
committer | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-05-13 17:29:28 -0400 |
commit | b30acce599e25e803ba333217d3b0d49d1815169 (patch) | |
tree | 9c12b98a82ea0666d9ba8b5925b51a7e547f1896 | |
parent | 46588aa62d444c5f0a538cccec357a80cd191b93 (diff) | |
parent | cfcd03a7c59eaa6b81de8c767bbd91e6d278c0f2 (diff) | |
download | puppet-vcsrepo-b30acce599e25e803ba333217d3b0d49d1815169.tar.gz puppet-vcsrepo-b30acce599e25e803ba333217d3b0d49d1815169.tar.bz2 |
Merge pull request #138 from cyberious/FM-1284
Fix issue where force=>true was not destroying repository then recreatin...
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 5 | ||||
-rw-r--r-- | lib/puppet/type/vcsrepo.rb | 8 | ||||
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/git_spec.rb | 19 |
3 files changed, 28 insertions, 4 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index b2e893b..fafe4bf 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -140,7 +140,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) if @resource.value(:remote) != 'origin' args.push('--origin', @resource.value(:remote)) end - if !File.exist?(File.join(@resource.value(:path), '.git')) + if !working_copy_exists? args.push(source, path) Dir.chdir("/") do git_with_identity(*args) @@ -271,6 +271,9 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) end def get_revision(rev) + if @resource.value(:force) && working_copy_exists? + create + end if !working_copy_exists? create end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb index 1dab2b9..3dd7bc6 100644 --- a/lib/puppet/type/vcsrepo.rb +++ b/lib/puppet/type/vcsrepo.rb @@ -76,7 +76,7 @@ Puppet::Type.newtype(:vcsrepo) do end newvalue :latest, :required_features => [:reference_tracking] do - if provider.exists? + if provider.exists? && !@resource.value(:force) if provider.respond_to?(:update_references) provider.update_references end @@ -97,6 +97,12 @@ Puppet::Type.newtype(:vcsrepo) do prov = @resource.provider if prov if prov.working_copy_exists? + if @resource.value(:force) + notice "Deleting current repository before recloning" + prov.destroy + notice "Create repository from latest" + prov.create + end (@should.include?(:latest) && prov.latest?) ? :latest : :present elsif prov.class.feature?(:bare_repositories) and prov.bare_exists? :bare diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index ba726fa..ad6ed08 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -9,6 +9,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do :revision => '2634', :source => 'git@repo', :path => '/tmp/test', + :force => false })} let(:provider) { resource.provider } @@ -151,12 +152,26 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do provider.expects(:convert_working_copy_to_bare) provider.create end + it "should clone overtop it using force" do + resource[:force] = true + Dir.expects(:chdir).with('/').at_least_once.yields + Dir.expects(:chdir).with('/tmp/test').at_least_once.yields + provider.expects(:path_exists?).returns(true) + provider.expects(:path_empty?).returns(false) + provider.destroy + provider.expects(:git).with('clone',resource.value(:source), resource.value(:path)) + provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create + end end context "when the path is not empty and not a repository" do it "should raise an exception" do - expects_directory?(true) + provider.expects(:path_exists?).returns(true) provider.expects(:path_empty?).returns(false) + provider.expects(:working_copy_exists?).returns(false) proc { provider.create }.should raise_error(Puppet::Error) end end @@ -390,7 +405,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end - describe 'convert_bare_to_working_copy' do + describe 'convert_bare_to_working_copy' do it do FileUtils.expects(:mv).returns(true) FileUtils.expects(:mkdir).returns(true) |