1 require "chef/mixin/shell_out"
6 extend Chef::Mixin::ShellOut
8 def shell_out!(*args, **options)
9 options = args.pop if options.empty? && args.last.is_a?(Hash)
11 super(*args, **options)
15 if current_repository_matches_target_repository?
16 c = scm :update, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", new_resource.destination
17 Chef::Log.debug "#{new_resource} updated working copy #{new_resource.destination} to revision #{new_resource.revision}"
19 c = scm :switch, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", "--ignore-ancestry", new_resource.repository, new_resource.destination
20 Chef::Log.debug "#{new_resource} updated working copy #{new_resource.destination} to #{new_resource.repository} revision #{new_resource.revision}"
25 def current_repository
26 @current_repository ||= repo_attrs["URL"]
29 def current_repository_matches_target_repository?
30 !current_repository.nil? && (new_resource.repository == current_repository)
34 return {} unless ::File.exist?(::File.join(new_resource.destination, ".svn"))
36 @repo_attrs ||= svn_info.lines.each_with_object({}) do |line, attrs|
37 next unless line =~ SVN_INFO_PATTERN
39 property = Regexp.last_match[1]
40 value = Regexp.last_match[2]
41 attrs[property] = value
44 raise "Could not parse `svn info` data: #{svn_info}" if @repo_attrs.empty?
51 shell_out!(command, **run_options(:cwd => cwd, :returns => [0, 1])).stdout
55 @revision_int ||= if new_resource.revision =~ /^\d+$/
58 command = scm(:info, new_resource.repository, new_resource.svn_info_args, authentication, "-r#{new_resource.revision}")
59 svn_info = shell_out!(command, **run_options(:returns => [0, 1])).stdout
61 extract_revision_info(svn_info)