summaryrefslogtreecommitdiff
path: root/chef/lib/chef/knife/cookbook_site_vendor.rb
diff options
context:
space:
mode:
authorAdam Jacob <adam@opscode.com>2010-04-15 14:45:17 -0700
committerAdam Jacob <adam@opscode.com>2010-04-15 14:45:17 -0700
commit73dab4a49401414877340686a442d0ea6e9c66e5 (patch)
tree177ee6606a89465e25b77e45c8edcd8bac06afca /chef/lib/chef/knife/cookbook_site_vendor.rb
parent098650220d9b454e364ac7635b65cb691d07c16d (diff)
downloadchef-73dab4a49401414877340686a442d0ea6e9c66e5.tar.gz
Adding dependency support for vendoring
Diffstat (limited to 'chef/lib/chef/knife/cookbook_site_vendor.rb')
-rw-r--r--chef/lib/chef/knife/cookbook_site_vendor.rb55
1 files changed, 39 insertions, 16 deletions
diff --git a/chef/lib/chef/knife/cookbook_site_vendor.rb b/chef/lib/chef/knife/cookbook_site_vendor.rb
index 1e74d1036f..00ceac6ff1 100644
--- a/chef/lib/chef/knife/cookbook_site_vendor.rb
+++ b/chef/lib/chef/knife/cookbook_site_vendor.rb
@@ -17,6 +17,7 @@
#
require 'chef/knife'
+require 'chef/cookbook/metadata'
class Chef
class Knife
@@ -24,6 +25,12 @@ class Chef
banner "Sub-Command: cookbook site vendor COOKBOOK [VERSION] (options)"
+ option :deps,
+ :short => "-d",
+ :long => "--dependencies",
+ :boolean => true,
+ :description => "Grab dependencies automatically"
+
def run
vendor_path = File.join(Chef::Config[:cookbook_path].first)
cookbook_path = File.join(vendor_path, name_args[0])
@@ -53,29 +60,45 @@ class Chef
Chef::Mixin::Command.run_command(:command => "rm #{upstream_file}", :cwd => vendor_path)
Chef::Log.info("Adding changes.")
Chef::Mixin::Command.run_command(:command => "git add #{name_args[0]}", :cwd => vendor_path)
+
Chef::Log.info("Committing changes.")
+ changes = true
begin
Chef::Mixin::Command.run_command(:command => "git commit -a -m 'Import #{name_args[0]} version #{download.version}'", :cwd => vendor_path)
rescue Chef::Exceptions::Exec => e
Chef::Log.warn("Checking out the master branch.")
- Chef::Log.warn("No changes from current vendor #{name_args[0]}, aborting!")
+ Chef::Log.warn("No changes from current vendor #{name_args[0]}")
Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
- exit 1
+ changes = false
end
- Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.")
- Chef::Mixin::Command.run_command(:command => "git tag -f chef-vendor-#{name_args[0]}-#{download.version}", :cwd => vendor_path)
- Chef::Log.info("Checking out the master branch.")
- Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
- Chef::Log.info("Merging changes from #{name_args[0]} version #{download.version}.")
-
- Dir.chdir(vendor_path) do
- if system("git merge #{branch_name}")
- Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!")
- exit 0
- else
- Chef::Log.error("You have merge conflicts - please resolve manually!")
- Chef::Log.error("(Hint: cd #{vendor_path}; git status)")
- exit 1
+
+ if changes
+ Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.")
+ Chef::Mixin::Command.run_command(:command => "git tag -f chef-vendor-#{name_args[0]}-#{download.version}", :cwd => vendor_path)
+ Chef::Log.info("Checking out the master branch.")
+ Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
+ Chef::Log.info("Merging changes from #{name_args[0]} version #{download.version}.")
+
+ Dir.chdir(vendor_path) do
+ if system("git merge #{branch_name}")
+ Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!")
+ else
+ Chef::Log.error("You have merge conflicts - please resolve manually!")
+ Chef::Log.error("(Hint: cd #{vendor_path}; git status)")
+ exit 1
+ end
+ end
+ end
+
+ if config[:deps]
+ md = Chef::Cookbook::Metadata.new
+ md.from_file(File.join(cookbook_path, "metadata.rb"))
+ md.dependencies.each do |cookbook, version_list|
+ # Doesn't do versions.. yet
+ nv = Chef::Knife::CookbookSiteVendor.new
+ nv.config = config
+ nv.name_args = [ cookbook ]
+ nv.run
end
end
end