def run
extend Chef::Mixin::ShellOut
if config[:cookbook_path]
Chef::Config[:cookbook_path] = config[:cookbook_path]
else
config[:cookbook_path] = Chef::Config[:cookbook_path]
end
@cookbook_name = parse_name_args!
@install_path = File.expand_path(Array(config[:cookbook_path]).first)
ui.info "Installing #@cookbook_name to #{@install_path}"
@repo = CookbookSCMRepo.new(@install_path, ui, config)
upstream_file = File.join(@install_path, "#{@cookbook_name}.tar.gz")
@repo.sanity_check
unless config[:use_current_branch]
@repo.reset_to_default_state
@repo.prepare_to_import(@cookbook_name)
end
downloader = download_cookbook_to(upstream_file)
clear_existing_files(File.join(@install_path, @cookbook_name))
extract_cookbook(upstream_file, downloader.version)
ui.info("removing downloaded tarball")
File.unlink(upstream_file)
if @repo.finalize_updates_to(@cookbook_name, downloader.version)
unless config[:use_current_branch]
@repo.reset_to_default_state
end
@repo.merge_updates_from(@cookbook_name, downloader.version)
else
unless config[:use_current_branch]
@repo.reset_to_default_state
end
end
unless config[:no_deps]
md = Chef::Cookbook::Metadata.new
md.from_file(File.join(@install_path, @cookbook_name, "metadata.rb"))
md.dependencies.each do |cookbook, version_list|
nv = self.class.new
nv.config = config
nv.name_args = [ cookbook ]
nv.run
end
end
end