]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/libraries/subversion.rb
Fix argument order to each_with_object
[chef.git] / cookbooks / chef / libraries / subversion.rb
1 class Chef
2   class Provider
3     class Subversion
4       def sync_command
5         if current_repository_matches_target_repository?
6           c = scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
7           Chef::Log.debug "#{@new_resource} updated working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
8         else
9           c = scm :switch, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.repository, @new_resource.destination
10           Chef::Log.debug "#{@new_resource} updated working copy #{@new_resource.destination} to #{@new_resource.repository} revision #{@new_resource.revision}"
11         end
12         c
13       end
14
15       def current_repository
16         @current_repository ||= repo_attrs["URL"]
17       end
18
19       def current_repository_matches_target_repository?
20         (!current_repository.nil?) && (@new_resource.repository == current_repository)
21       end
22
23       def repo_attrs
24         return {} unless ::File.exist?(::File.join(@new_resource.destination, ".svn"))
25
26         @repo_attrs ||= svn_info.lines.each_with_object({}) do |line, attrs|
27           if line =~ SVN_INFO_PATTERN
28             property, value = Regexp.last_match[1], Regexp.last_match[2]
29             attrs[property] = value
30           else
31             fail "Could not parse `svn info` data: #{line}"
32           end
33         end
34       end
35
36       def svn_info
37         command = scm(:info)
38         status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
39
40         unless [0, 1].include?(status.exitstatus)
41           handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
42         end
43
44         svn_info
45       end
46     end
47   end
48 end