]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/libraries/subversion.rb
Imagery - add root layer support
[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           fail "Could not parse `svn info` data: #{line}" unless line =~ SVN_INFO_PATTERN
28
29           property = Regexp.last_match[1]
30           value = Regexp.last_match[2]
31           attrs[property] = value
32         end
33       end
34
35       def svn_info
36         command = scm(:info)
37         status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
38
39         unless [0, 1].include?(status.exitstatus)
40           handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
41         end
42
43         svn_info
44       end
45     end
46   end
47 end