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