(MODULES-1551) Add support for SVN conflict handling
authorDaniel DiSisto <ddisisto@gmail.com>
Fri, 6 Mar 2015 06:01:38 +0000 (17:01 +1100)
committerDaniel DiSisto <ddisisto@gmail.com>
Fri, 6 Mar 2015 06:01:38 +0000 (17:01 +1100)
lib/puppet/provider/vcsrepo/svn.rb
lib/puppet/type/vcsrepo.rb
spec/unit/puppet/provider/vcsrepo/svn_spec.rb

index a1b1714..905d5ad 100644 (file)
@@ -7,7 +7,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
            :svnadmin => 'svnadmin',
            :svnlook  => 'svnlook'
 
-  has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration
+  has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration, :conflict
 
   def create
     if !@resource.value(:source)
@@ -92,6 +92,11 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
            else
              buildargs.push('update', '-r', desired)
            end
+
+    if @resource.value(:conflict)
+      args.push('--accept', @resource.value(:conflict))
+    end
+
     at_path do
       svn(*args)
     end
index 3bf4029..52eace8 100644 (file)
@@ -46,6 +46,9 @@ Puppet::Type.newtype(:vcsrepo) do
   feature :submodules,
           "The repository contains submodules which can be optionally initialized"
 
+  feature :conflict,
+          "The provider supports automatic conflict resolution"
+
   ensurable do
     attr_accessor :latest
 
@@ -214,6 +217,10 @@ Puppet::Type.newtype(:vcsrepo) do
     defaultto true
   end
 
+  newparam :conflict do
+    desc "The action to take if conflicts exist between repository and working copy"
+  end
+
   autorequire(:package) do
     ['git', 'git-core']
   end
index 494da52..77f0e03 100644 (file)
@@ -83,10 +83,22 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do
     before do
       @revision = '30'
     end
-    it "should use 'svn update'" do
-      expects_chdir
-      provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
-      provider.revision = @revision
+    context 'with conflict' do
+      it "should use 'svn update'" do
+        resource[:conflict] = 'theirs-full'
+        expects_chdir
+        provider.expects(:svn).with('--non-interactive', 'update',
+                                    '-r', @revision,
+                                    '--accept', resource.value(:conflict))
+        provider.revision = @revision
+      end
+    end
+    context 'without conflict' do
+      it "should use 'svn update'" do
+        expects_chdir
+        provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
+        provider.revision = @revision
+      end
     end
   end
 
@@ -94,11 +106,24 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do
     before do
       @revision = '30'
     end
-    it "should use 'svn switch'" do
-      resource[:source] = 'an-unimportant-value'
-      expects_chdir
-      provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value')
-      provider.revision = @revision
+    context 'with conflict' do
+      it "should use 'svn switch'" do
+        resource[:source] = 'an-unimportant-value'
+        resource[:conflict] = 'theirs-full'
+        expects_chdir
+        provider.expects(:svn).with('--non-interactive', 'switch',
+                                    '-r', @revision, 'an-unimportant-value',
+                                    '--accept', resource.value(:conflict))
+        provider.revision = @revision
+      end
+    end
+    context 'without conflict' do
+      it "should use 'svn switch'" do
+        resource[:source] = 'an-unimportant-value'
+        expects_chdir
+        provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value')
+        provider.revision = @revision
+      end
     end
   end