Fix some issues identified by rubocop
[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.inject({}) do |attrs, line|
27           if line =~ SVN_INFO_PATTERN
28             property, value = $1, $2
29             attrs[property] = value
30           else
31             raise "Could not parse `svn info` data: #{line}"
32           end
33           attrs
34         end
35       end
36
37       def svn_info
38         command = scm(:info)
39         status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
40
41         unless [0,1].include?(status.exitstatus)
42           handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
43         end
44
45         svn_info
46       end
47     end
48   end
49 end