]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/libraries/subversion.rb
Remove old machines from dhcp and add IC machines
[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, proxy, "-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, proxy, "-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           next unless line =~ SVN_INFO_PATTERN
32           property = Regexp.last_match[1]
33           value = Regexp.last_match[2]
34           attrs[property] = value
35         end
36
37         raise "Could not parse `svn info` data: #{svn_info}" if @repo_attrs.empty?
38
39         @repo_attrs
40       end
41
42       def svn_info
43         command = scm(:info)
44         shell_out!(command, run_options(:cwd => cwd, :returns => [0, 1])).stdout
45       end
46     end
47   end
48 end