chef 0.9.12 → 0.9.14.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/distro/arch/etc/conf.d/chef-client.conf +5 -0
  2. data/distro/arch/etc/conf.d/chef-server-webui.conf +10 -0
  3. data/distro/arch/etc/conf.d/chef-server.conf +10 -0
  4. data/distro/arch/etc/conf.d/chef-solr-indexer.conf +8 -0
  5. data/distro/arch/etc/conf.d/chef-solr.conf +8 -0
  6. data/distro/arch/etc/rc.d/chef-client +76 -0
  7. data/distro/arch/etc/rc.d/chef-server +82 -0
  8. data/distro/arch/etc/rc.d/chef-server-webui +82 -0
  9. data/distro/arch/etc/rc.d/chef-solr +82 -0
  10. data/distro/arch/etc/rc.d/chef-solr-indexer +82 -0
  11. data/distro/common/markdown/knife.mkd +34 -1
  12. data/distro/debian/etc/default/chef-solr +1 -0
  13. data/distro/debian/etc/init.d/chef-client +1 -1
  14. data/distro/debian/etc/init.d/chef-solr +39 -40
  15. data/distro/debian/etc/init.d/chef-solr-indexer +1 -1
  16. data/distro/redhat/etc/init.d/chef-client +1 -1
  17. data/lib/chef.rb +1 -0
  18. data/lib/chef/api_client.rb +1 -1
  19. data/lib/chef/application/agent.rb +1 -1
  20. data/lib/chef/application/client.rb +1 -1
  21. data/lib/chef/application/solo.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +2 -2
  23. data/lib/chef/cookbook/syntax_check.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +5 -1
  25. data/lib/chef/couchdb.rb +1 -1
  26. data/lib/chef/data_bag.rb +1 -1
  27. data/lib/chef/data_bag_item.rb +35 -9
  28. data/lib/chef/exceptions.rb +2 -0
  29. data/lib/chef/file_cache.rb +1 -1
  30. data/lib/chef/handler/json_file.rb +1 -1
  31. data/lib/chef/index_queue/amqp_client.rb +2 -2
  32. data/lib/chef/index_queue/consumer.rb +2 -2
  33. data/lib/chef/json.rb +52 -0
  34. data/lib/chef/knife.rb +6 -6
  35. data/lib/chef/knife/bluebox_images_list.rb +54 -0
  36. data/lib/chef/knife/bluebox_server_create.rb +157 -0
  37. data/lib/chef/knife/bluebox_server_delete.rb +63 -0
  38. data/lib/chef/knife/bluebox_server_list.rb +59 -0
  39. data/lib/chef/knife/bootstrap.rb +3 -1
  40. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  41. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  42. data/lib/chef/knife/bootstrap/fedora13-gems.erb +1 -1
  43. data/lib/chef/knife/client_bulk_delete.rb +1 -1
  44. data/lib/chef/knife/client_create.rb +1 -1
  45. data/lib/chef/knife/client_delete.rb +1 -1
  46. data/lib/chef/knife/client_edit.rb +1 -1
  47. data/lib/chef/knife/client_list.rb +1 -1
  48. data/lib/chef/knife/client_reregister.rb +1 -1
  49. data/lib/chef/knife/client_show.rb +1 -1
  50. data/lib/chef/knife/cookbook_create.rb +1 -1
  51. data/lib/chef/knife/cookbook_list.rb +1 -1
  52. data/lib/chef/knife/cookbook_metadata.rb +1 -1
  53. data/lib/chef/knife/cookbook_show.rb +10 -18
  54. data/lib/chef/knife/cookbook_site_share.rb +1 -1
  55. data/lib/chef/knife/cookbook_site_vendor.rb +17 -11
  56. data/lib/chef/knife/ec2_instance_data.rb +1 -1
  57. data/lib/chef/knife/ec2_server_create.rb +8 -6
  58. data/lib/chef/knife/ec2_server_delete.rb +5 -8
  59. data/lib/chef/knife/ec2_server_list.rb +5 -4
  60. data/lib/chef/knife/exec.rb +1 -1
  61. data/lib/chef/knife/node_bulk_delete.rb +1 -1
  62. data/lib/chef/knife/node_create.rb +1 -1
  63. data/lib/chef/knife/node_delete.rb +1 -1
  64. data/lib/chef/knife/node_edit.rb +1 -1
  65. data/lib/chef/knife/node_from_file.rb +2 -2
  66. data/lib/chef/knife/node_list.rb +1 -1
  67. data/lib/chef/knife/node_run_list_add.rb +1 -1
  68. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  69. data/lib/chef/knife/node_show.rb +1 -1
  70. data/lib/chef/knife/rackspace_server_create.rb +98 -70
  71. data/lib/chef/knife/rackspace_server_delete.rb +2 -2
  72. data/lib/chef/knife/rackspace_server_list.rb +2 -2
  73. data/lib/chef/knife/role_bulk_delete.rb +1 -1
  74. data/lib/chef/knife/role_create.rb +1 -1
  75. data/lib/chef/knife/role_delete.rb +1 -1
  76. data/lib/chef/knife/role_edit.rb +1 -1
  77. data/lib/chef/knife/role_from_file.rb +2 -2
  78. data/lib/chef/knife/role_list.rb +1 -1
  79. data/lib/chef/knife/role_show.rb +1 -1
  80. data/lib/chef/knife/slicehost_images_list.rb +2 -2
  81. data/lib/chef/knife/slicehost_server_create.rb +2 -2
  82. data/lib/chef/knife/slicehost_server_delete.rb +2 -2
  83. data/lib/chef/knife/slicehost_server_list.rb +2 -2
  84. data/lib/chef/knife/ssh.rb +36 -12
  85. data/lib/chef/knife/status.rb +1 -1
  86. data/lib/chef/knife/terremark_server_create.rb +1 -1
  87. data/lib/chef/knife/terremark_server_delete.rb +1 -1
  88. data/lib/chef/knife/terremark_server_list.rb +1 -1
  89. data/lib/chef/log.rb +31 -4
  90. data/lib/chef/mixin/command.rb +1 -1
  91. data/lib/chef/mixin/create_path.rb +1 -1
  92. data/lib/chef/mixin/recipe_definition_dsl_core.rb +1 -1
  93. data/lib/chef/monkey_patches/numeric.rb +7 -0
  94. data/lib/chef/node.rb +6 -8
  95. data/lib/chef/node/attribute.rb +24 -2
  96. data/lib/chef/openid_registration.rb +1 -1
  97. data/lib/chef/platform.rb +11 -0
  98. data/lib/chef/provider/breakpoint.rb +1 -1
  99. data/lib/chef/provider/cookbook_file.rb +1 -1
  100. data/lib/chef/provider/deploy/revision.rb +1 -1
  101. data/lib/chef/provider/deploy/timestamped.rb +1 -1
  102. data/lib/chef/provider/erl_call.rb +14 -2
  103. data/lib/chef/provider/git.rb +79 -55
  104. data/lib/chef/provider/group/pw.rb +1 -1
  105. data/lib/chef/provider/package/easy_install.rb +35 -13
  106. data/lib/chef/provider/service/debian.rb +65 -40
  107. data/lib/chef/provider/service/insserv.rb +52 -0
  108. data/lib/chef/provider/service/windows.rb +74 -57
  109. data/lib/chef/provider/subversion.rb +45 -10
  110. data/lib/chef/provider/user/pw.rb +1 -1
  111. data/lib/chef/providers.rb +1 -0
  112. data/lib/chef/resource/deploy_revision.rb +1 -1
  113. data/lib/chef/resource/easy_install_package.rb +16 -0
  114. data/lib/chef/resource/file.rb +8 -1
  115. data/lib/chef/resource_collection/stepable_iterator.rb +1 -1
  116. data/lib/chef/rest.rb +7 -7
  117. data/lib/chef/role.rb +2 -2
  118. data/lib/chef/run_status.rb +1 -1
  119. data/lib/chef/shef.rb +2 -2
  120. data/lib/chef/shef/ext.rb +2 -2
  121. data/lib/chef/shef/model_wrapper.rb +1 -1
  122. data/lib/chef/shef/shef_rest.rb +1 -1
  123. data/lib/chef/shef/shef_session.rb +13 -5
  124. data/lib/chef/tasks/chef_repo.rake +1 -1
  125. data/lib/chef/version.rb +1 -1
  126. data/lib/chef/webui_user.rb +1 -1
  127. metadata +329 -290
@@ -42,7 +42,7 @@ class Chef
42
42
  q.search(:node, query) do |node|
43
43
  all_nodes << node
44
44
  end
45
- all_nodes.sort { |n1, n2| n1["ohai_time"] <=> n2["ohai_time"] }.each do |node|
45
+ all_nodes.sort { |n1, n2| (n1["ohai_time"] or 0) <=> (n2["ohai_time"] or 0) }.each do |node|
46
46
  if node.has_key?("ec2")
47
47
  fqdn = node['ec2']['public_hostname']
48
48
  ipaddress = node['ec2']['public_ipv4']
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'json'
20
+ require 'chef/json'
21
21
  require 'tempfile'
22
22
 
23
23
  class Chef
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'json'
20
+ require 'chef/json'
21
21
 
22
22
  class Chef
23
23
  class Knife
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'json'
20
+ require 'chef/json'
21
21
  require 'tempfile'
22
22
 
23
23
  class Chef
@@ -43,13 +43,40 @@ class Chef
43
43
  end
44
44
  self.verbose
45
45
  end
46
-
47
- def method_missing(method_symbol, *args)
48
- self.verbose_logger.send(method_symbol, *args) if self.verbose
49
- logger.send(method_symbol, *args)
46
+
47
+ [:debug, :info, :warn, :error, :fatal].each do |method_name|
48
+ class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
49
+ def #{method_name}(msg=nil, &block)
50
+ @logger.#{method_name}(msg, &block)
51
+ end
52
+ METHOD_DEFN
53
+ end
54
+
55
+ [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
56
+ class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
57
+ def #{method_name}
58
+ @logger.#{method_name}
59
+ end
60
+ METHOD_DEFN
61
+ end
62
+
63
+ def <<(msg)
64
+ @logger << msg
65
+ end
66
+
67
+ def add(severity, message = nil, progname = nil, &block)
68
+ @logger.add(severity, message = nil, progname = nil, &block)
50
69
  end
70
+
51
71
  end
52
72
 
73
+ # NOTE: Mixlib::Log initially sets @logger to nil and depends on
74
+ # #init being called to initialize the logger. We don't want to
75
+ # incur extra method call overhead for every log message so we're
76
+ # accessing the logger by instance variable, which means we need to
77
+ # make Mixlib::Log initialize it.
78
+ init
79
+
53
80
  class Formatter
54
81
  def self.show_time=(*args)
55
82
  Mixlib::Log::Formatter.show_time = *args
@@ -142,7 +142,7 @@ class Chef
142
142
  end
143
143
 
144
144
  args[:cwd] ||= Dir.tmpdir
145
- unless File.directory?(args[:cwd])
145
+ unless ::File.directory?(args[:cwd])
146
146
  raise Chef::Exceptions::Exec, "#{args[:cwd]} does not exist or is not a directory"
147
147
  end
148
148
 
@@ -53,4 +53,4 @@ class Chef
53
53
 
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -78,4 +78,4 @@ class Chef
78
78
 
79
79
  end
80
80
  end
81
- end
81
+ end
@@ -0,0 +1,7 @@
1
+ unless 0.respond_to?(:fdiv)
2
+ class Numeric
3
+ def fdiv(other)
4
+ to_f / other
5
+ end
6
+ end
7
+ end
@@ -32,7 +32,7 @@ require 'chef/run_list'
32
32
  require 'chef/node/attribute'
33
33
  require 'chef/index_queue'
34
34
  require 'extlib'
35
- require 'json'
35
+ require 'chef/json'
36
36
 
37
37
  class Chef
38
38
  class Node
@@ -326,12 +326,11 @@ class Chef
326
326
  # run_state[:seen_recipes], which is populated by include_recipe
327
327
  # statements in the DSL (and thus would not be in the run list).
328
328
  #
329
- # NOTE: We believe this is dead code, but if it's not, please
330
- # email chef-dev@opscode.com. [cw,timh]
331
- # def recipe?(recipe_name)
332
- # run_list.include?(recipe_name) || run_state[:seen_recipes].include?(recipe_name)
333
- # end
334
-
329
+ # NOTE: It's used by cookbook authors
330
+ def recipe?(recipe_name)
331
+ run_list.include?(recipe_name) || run_state[:seen_recipes].include?(recipe_name)
332
+ end
333
+
335
334
  # Returns true if this Node expects a given role, false if not.
336
335
  def role?(role_name)
337
336
  run_list.include?("role[#{role_name}]")
@@ -596,6 +595,5 @@ class Chef
596
595
  self.from_file(attribute_filename)
597
596
  self
598
597
  end
599
-
600
598
  end
601
599
  end
@@ -450,14 +450,36 @@ class Chef
450
450
  end
451
451
  end
452
452
 
453
+ def delete(key)
454
+ [@automatic, @override, @normal, @default].inject(nil) do |return_value, attrs|
455
+ deleted_value = delete_from_component(attrs, key)
456
+ return_value || deleted_value
457
+ end
458
+ end
459
+
460
+ def delete_from_component(component_attrs, key)
461
+ # get the Hash-like object at the current nesting level:
462
+ nested_attrs = value_at_current_nesting(component_attrs, key)
463
+
464
+ if nested_attrs.respond_to?(:delete)
465
+ nested_attrs.delete(key)
466
+ else
467
+ nil
468
+ end
469
+ end
470
+
453
471
  def component_has_key?(component_attrs,key)
454
472
  # get the Hash-like object at the current nesting level:
455
- nested_attrs = @current_nesting_level.inject(component_attrs) do |subtree, intermediate_key|
473
+ nested_attrs = value_at_current_nesting(component_attrs, key)
474
+ nested_attrs.respond_to?(:key?) && nested_attrs.key?(key)
475
+ end
476
+
477
+ def value_at_current_nesting(component_attrs, key)
478
+ @current_nesting_level.inject(component_attrs) do |subtree, intermediate_key|
456
479
  # if the intermediate value isn't a hash or doesn't have the intermediate key,
457
480
  # it can't have the bottom-level key we're looking for.
458
481
  (subtree.respond_to?(:key?) && subtree[intermediate_key]) or (return false)
459
482
  end
460
- nested_attrs.respond_to?(:key?) && nested_attrs.key?(key)
461
483
  end
462
484
 
463
485
  end
@@ -21,7 +21,7 @@ require 'chef/mixin/params_validate'
21
21
  require 'chef/couchdb'
22
22
  require 'chef/index_queue'
23
23
  require 'digest/sha1'
24
- require 'json'
24
+ require 'chef/json'
25
25
 
26
26
  class Chef
27
27
  class OpenIDRegistration
@@ -70,6 +70,17 @@ class Chef
70
70
  :service => Chef::Provider::Service::Debian,
71
71
  :cron => Chef::Provider::Cron,
72
72
  :mdadm => Chef::Provider::Mdadm
73
+ },
74
+ "6.0" => {
75
+ :service => Chef::Provider::Service::Insserv
76
+ }
77
+ },
78
+ :xenserver => {
79
+ :default => {
80
+ :service => Chef::Provider::Service::Redhat,
81
+ :cron => Chef::Provider::Cron,
82
+ :package => Chef::Provider::Package::Yum,
83
+ :mdadm => Chef::Provider::Mdadm
73
84
  }
74
85
  },
75
86
  :centos => {
@@ -33,4 +33,4 @@ class Chef
33
33
 
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -97,4 +97,4 @@ class Chef
97
97
 
98
98
  end
99
99
  end
100
- end
100
+ end
@@ -56,7 +56,7 @@ class Chef
56
56
 
57
57
  def load_cache
58
58
  begin
59
- JSON.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
59
+ Chef::JSON.from_json(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
60
60
  rescue Chef::Exceptions::FileNotFound
61
61
  sorted_releases_from_filesystem
62
62
  end
@@ -30,4 +30,4 @@ class Chef
30
30
  end
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -55,16 +55,28 @@ class Chef
55
55
 
56
56
  command = "erl_call -e #{distributed} #{node} #{cookie}"
57
57
 
58
- status = popen4(command, :waitlast => true) do |pid, stdin, stdout, stderr|
58
+ begin
59
+ pid, stdin, stdout, stderr = popen4(command, :waitlast => true)
60
+
59
61
  Chef::Log.debug("Running erl_call[#{@new_resource.name}]")
60
62
  Chef::Log.debug("erl_call[#{@new_resource.name}] command: #{command}")
61
63
  Chef::Log.debug("erl_call[#{@new_resource.name}] code: #{@new_resource.code}")
62
- @new_resource.code.each_line { |line| stdin.puts "#{line.chomp!}" }
64
+
65
+ @new_resource.code.each_line { |line| stdin.puts(line.chomp) }
66
+
63
67
  stdin.close
68
+
64
69
  Chef::Log.info("Ran erl_call[#{@new_resource.name}] successfully")
65
70
  Chef::Log.debug("erl_call[#{@new_resource.name}] output: ")
71
+
66
72
  stdout.each_line { |line| Chef::Log.debug("#{line}")}
73
+ stderr.each_line { |line| Chef::Log.debug("#{line}")}
74
+ stdout.close
75
+ stderr.close
76
+ ensure
77
+ Process.wait(pid) if pid
67
78
  end
79
+
68
80
  end
69
81
 
70
82
  end
@@ -36,7 +36,9 @@ class Chef
36
36
  end
37
37
 
38
38
  def action_checkout
39
- if !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination) == ['.','..']
39
+ assert_target_directory_valid!
40
+
41
+ if target_dir_non_existant_or_empty?
40
42
  clone
41
43
  checkout
42
44
  enable_submodules
@@ -53,24 +55,40 @@ class Chef
53
55
  end
54
56
 
55
57
  def action_sync
56
- if !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination) == ['.','..']
57
- action_checkout
58
- @new_resource.updated_by_last_action(true)
59
- else
58
+ assert_target_directory_valid!
59
+
60
+ if existing_git_clone?
60
61
  current_rev = find_current_revision
61
- Chef::Log.debug "#{@new_resource} revision: #{current_rev}"
62
- sync
63
- enable_submodules
64
- new_rev = find_current_revision
65
- if current_rev == new_rev
66
- @new_resource.updated_by_last_action(false)
67
- else
68
- Chef::Log.info "#{@new_resource} updated revision is: #{new_rev}"
62
+ Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{target_revision}"
63
+ unless current_revision_matches_target_revision?
64
+ fetch_updates
65
+ enable_submodules
66
+ Chef::Log.info "#{@new_resource} updated to revision: #{target_revision}"
69
67
  @new_resource.updated_by_last_action(true)
70
68
  end
69
+
70
+ else
71
+ action_checkout
72
+ @new_resource.updated_by_last_action(true)
71
73
  end
72
74
  end
73
-
75
+
76
+ def assert_target_directory_valid!
77
+ target_parent_directory = ::File.dirname(@new_resource.destination)
78
+ unless ::File.directory?(target_parent_directory)
79
+ msg = "Cannot clone #{@new_resource} to #{@new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist"
80
+ raise Chef::Exceptions::MissingParentDirectory, msg
81
+ end
82
+ end
83
+
84
+ def existing_git_clone?
85
+ ::File.exist?(::File.join(@new_resource.destination, ".git"))
86
+ end
87
+
88
+ def target_dir_non_existant_or_empty?
89
+ !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination).sort == ['.','..']
90
+ end
91
+
74
92
  def find_current_revision
75
93
  if ::File.exist?(::File.join(cwd, ".git"))
76
94
  status, result, error_message = output_of_command("git rev-parse HEAD", run_options(:cwd=>cwd))
@@ -92,73 +110,80 @@ class Chef
92
110
 
93
111
  Chef::Log.info "Cloning repo #{@new_resource.repository} to #{@new_resource.destination}"
94
112
 
95
- clone_cmd = "#{git} clone #{args.join(' ')} #{@new_resource.repository} #{@new_resource.destination}"
113
+ clone_cmd = "git clone #{args.join(' ')} #{@new_resource.repository} #{@new_resource.destination}"
96
114
  run_command(run_options(:command => clone_cmd))
97
115
  end
98
116
 
99
117
  def checkout
100
- sha_ref = revision_sha
118
+ sha_ref = target_revision
101
119
  Chef::Log.info "Checking out branch: #{@new_resource.revision} reference: #{sha_ref}"
102
120
  # checkout into a local branch rather than a detached HEAD
103
- run_command(run_options(:command => "#{git} checkout -b deploy #{sha_ref}", :cwd => @new_resource.destination))
121
+ run_command(run_options(:command => "git checkout -b deploy #{sha_ref}", :cwd => @new_resource.destination))
104
122
  end
105
123
 
106
124
  def enable_submodules
107
125
  if @new_resource.enable_submodules
108
126
  Chef::Log.info "Enabling git submodules"
109
- command = "#{git} submodule init && #{git} submodule update"
127
+ command = "git submodule init && git submodule update"
110
128
  run_command(run_options(:command => command, :cwd => @new_resource.destination))
111
129
  end
112
130
  end
113
131
 
114
- def sync
115
- revision = revision_sha
116
- sync_command = []
117
-
118
- # Use git-config to setup a remote tracking branches. Could use
119
- # git-remote but it complains when a remote of the same name already
120
- # exists, git-config will just silenty overwrite the setting every
121
- # time. This could cause wierd-ness in the remote cache if the url
122
- # changes between calls, but as long as the repositories are all
123
- # based from each other it should still work fine.
124
- if @new_resource.remote != 'origin'
125
- Chef::Log.info "Configuring remote tracking branches for repository #{@new_resource.repository} "+
126
- "at remote #{@new_resource.remote}"
127
- sync_command << "#{git} config remote.#{@new_resource.remote}.url #{@new_resource.repository}"
128
- sync_command << "#{git} config remote.#{@new_resource.remote}.fetch +refs/heads/*:refs/remotes/#{@new_resource.remote}/*"
129
- end
132
+ def fetch_updates
133
+ setup_remote_tracking_branches if @new_resource.remote != 'origin'
130
134
 
131
135
  # since we're in a local branch already, just reset to specified revision rather than merge
132
- sync_command << "#{git} fetch #{@new_resource.remote} && #{git} fetch #{@new_resource.remote} --tags && #{git} reset --hard #{revision}"
133
- Chef::Log.info "Fetching updates from #{new_resource.remote} and resetting to revison #{revision}"
134
- run_command(run_options(:command => sync_command.join(" && "), :cwd => @new_resource.destination))
136
+ fetch_command = "git fetch #{@new_resource.remote} && git fetch #{@new_resource.remote} --tags && git reset --hard #{target_revision}"
137
+ Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revison #{target_revision}"
138
+ run_command(run_options(:command => fetch_command, :cwd => @new_resource.destination))
135
139
  end
136
-
137
- def revision_sha
138
- @revision_sha ||= begin
140
+
141
+ # Use git-config to setup a remote tracking branches. Could use
142
+ # git-remote but it complains when a remote of the same name already
143
+ # exists, git-config will just silenty overwrite the setting every
144
+ # time. This could cause wierd-ness in the remote cache if the url
145
+ # changes between calls, but as long as the repositories are all
146
+ # based from each other it should still work fine.
147
+ def setup_remote_tracking_branches
148
+ command = []
149
+
150
+ Chef::Log.info "Configuring remote tracking branches for repository #{@new_resource.repository} "+
151
+ "at remote #{@new_resource.remote}"
152
+ command << "git config remote.#{@new_resource.remote}.url #{@new_resource.repository}"
153
+ command << "git config remote.#{@new_resource.remote}.fetch +refs/heads/*:refs/remotes/#{@new_resource.remote}/*"
154
+ run_command(run_options(:command => command.join(" && "), :cwd => @new_resource.destination))
155
+ end
156
+
157
+ def current_revision_matches_target_revision?
158
+ (!@current_resource.revision.nil?) && (target_revision.strip.to_i(16) == @current_resource.revision.strip.to_i(16))
159
+ end
160
+
161
+ def target_revision
162
+ @target_revision ||= begin
139
163
  assert_revision_not_remote
140
164
 
141
165
  if sha_hash?(@new_resource.revision)
142
- @revision_sha = @new_resource.revision
166
+ @target_revision = @new_resource.revision
143
167
  else
144
168
  resolved_reference = remote_resolve_reference
145
- @revision_sha = extract_revision(resolved_reference)
169
+ @target_revision = extract_revision(resolved_reference)
146
170
  end
147
171
  end
148
172
  end
149
173
 
150
- alias :revision_slug :revision_sha
174
+ alias :revision_slug :target_revision
151
175
 
152
176
  def remote_resolve_reference
153
- command = scm('ls-remote', @new_resource.repository, @new_resource.revision)
177
+ command = git('ls-remote', @new_resource.repository, @new_resource.revision)
154
178
  Chef::Log.debug("Executing #{command}")
155
179
  begin
156
180
  status, result, error_message = output_of_command(command, run_options)
157
181
  handle_command_failures(status, "STDOUT: #{result}\nSTDERR: #{error_message}")
158
- rescue RuntimeError => e
159
- raise RuntimeError, e.message + "\n" + "Could not access the remote Git repository. "+
160
- "If this is a private repository, please verify that the deploy key for your application " +
161
- "has been added to your remote Git account."
182
+ rescue Chef::Exceptions::Exec => e
183
+ msg = "Could not access the remote Git repository. If this is a private repository, "
184
+ msg << "verify that the deploy key for your application has been added to your remote Git account.\n"
185
+ msg << e.message
186
+ raise Chef::Exceptions::Exec, msg
162
187
  end
163
188
  result
164
189
  end
@@ -176,14 +201,10 @@ class Chef
176
201
  @new_resource.destination
177
202
  end
178
203
 
179
- def scm(*args)
180
- [git, *args].compact.join(" ")
204
+ def git(*args)
205
+ ["git", *args].compact.join(" ")
181
206
  end
182
207
 
183
- def git
184
- 'git'
185
- end
186
-
187
208
  def sha_hash?(string)
188
209
  string =~ /^[0-9a-f]{40}$/
189
210
  end
@@ -201,7 +222,10 @@ class Chef
201
222
 
202
223
  def extract_revision(resolved_reference)
203
224
  unless resolved_reference =~ /^([0-9a-f]{40})\s+(\S+)/
204
- raise "Unable to resolve reference for '#{resolved_reference}' on repository '#{@new_resource.repository}'."
225
+ msg = "Unable to parse SHA reference for '#{@new_resource.revision}' in repository '#{@new_resource.repository}'. "
226
+ msg << "Verify your (case-sensitive) repository URL and revision.\n"
227
+ msg << "`git ls-remote` output: #{resolved_reference}"
228
+ raise Chef::Exceptions::UnresolvableGitReference, msg
205
229
  end
206
230
  $1
207
231
  end