diff options
author | Seth Chisamore <schisamo@opscode.com> | 2011-02-01 22:35:31 -0500 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-02-01 19:54:02 -0800 |
commit | 99d5a241849450dedd3c361c59866b947e1de721 (patch) | |
tree | fc105159ba2bd2e42f2f56affd1ebf6c37064c1e | |
parent | c9bea2d368381fa3944e9e05539c43829cfd4f36 (diff) | |
download | chef-99d5a241849450dedd3c361c59866b947e1de721.tar.gz |
CHEF-2002, sync actions should be idempotent
-rw-r--r-- | chef/lib/chef/provider/subversion.rb | 14 | ||||
-rw-r--r-- | chef/spec/unit/provider/subversion_spec.rb | 11 |
2 files changed, 23 insertions, 2 deletions
diff --git a/chef/lib/chef/provider/subversion.rb b/chef/lib/chef/provider/subversion.rb index 642560fe0a..1f94c122e1 100644 --- a/chef/lib/chef/provider/subversion.rb +++ b/chef/lib/chef/provider/subversion.rb @@ -55,11 +55,17 @@ class Chef def action_sync if ::File.exist?(::File.join(@new_resource.destination, ".svn")) - run_command(run_options(:command => sync_command)) + current_rev = find_current_revision + Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{revision_int}" + unless current_revision_matches_target_revision? + run_command(run_options(:command => sync_command)) + Chef::Log.info "#{@new_resource} updated to revision: #{revision_int}" + @new_resource.updated_by_last_action(true) + end else action_checkout + @new_resource.updated_by_last_action(true) end - @new_resource.updated_by_last_action(true) end def sync_command @@ -110,6 +116,10 @@ class Chef extract_revision_info(svn_info) end + def current_revision_matches_target_revision? + (!@current_resource.revision.nil?) && (revision_int.strip.to_i == @current_resource.revision.strip.to_i) + end + def run_options(run_opts={}) run_opts[:user] = @new_resource.user if @new_resource.user run_opts[:group] = @new_resource.group if @new_resource.group diff --git a/chef/spec/unit/provider/subversion_spec.rb b/chef/spec/unit/provider/subversion_spec.rb index 45ff69d2a7..dcc0b7667f 100644 --- a/chef/spec/unit/provider/subversion_spec.rb +++ b/chef/spec/unit/provider/subversion_spec.rb @@ -226,12 +226,23 @@ describe Chef::Provider::Subversion do it "runs the sync_command on action_sync if the deploy dir exists and isn't empty" do ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) + @provider.stub!(:find_current_revision).and_return("11410") + @provider.stub!(:current_revision_matches_target_revision?).and_return(false) expected_cmd = "svn update -q -r12345 /my/deploy/dir" @provider.should_receive(:run_command).with(:command => expected_cmd) @provider.action_sync @resource.should be_updated end + it "does not fetch any updates if the remote revision matches the current revision" do + ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) + #::File.stub!(:directory?).with("/my/deploy").and_return(true) + @provider.stub!(:find_current_revision).and_return('12345') + @provider.stub!(:current_revision_matches_target_revision?).and_return(true) + @provider.action_sync + @resource.should_not be_updated + end + it "runs the export_command on action_export" do expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" @provider.should_receive(:run_command).with(:command => expected_cmd) |