diff options
author | Adam Jacob <adam@opscode.com> | 2010-04-13 21:47:06 -0700 |
---|---|---|
committer | Adam Jacob <adam@opscode.com> | 2010-04-13 21:47:06 -0700 |
commit | ebd644e26d2fcbd36bdc64274628bb5ce5a40b66 (patch) | |
tree | e8e2a82ef9e2c8e56ec2cac568a3e82277ffb159 | |
parent | 5f45ea2a362a59cab0dc3a31302e2ab51eb34f7a (diff) | |
download | chef-ebd644e26d2fcbd36bdc64274628bb5ce5a40b66.tar.gz |
Adding cookbook site vendor supportalpha_deploy_4
-rw-r--r-- | chef/lib/chef/knife/cookbook_site_vendor.rb | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/chef/lib/chef/knife/cookbook_site_vendor.rb b/chef/lib/chef/knife/cookbook_site_vendor.rb index 56884d347f..a3b33a6d77 100644 --- a/chef/lib/chef/knife/cookbook_site_vendor.rb +++ b/chef/lib/chef/knife/cookbook_site_vendor.rb @@ -28,32 +28,56 @@ class Chef vendor_path = File.join(Chef::Config[:cookbook_path].first) cookbook_path = File.join(vendor_path, name_args[0]) upstream_file = File.join(vendor_path, "#{name_args[0]}.tar.gz") - branch_name = "#{name_args[0]}-chef-upstream" + branch_name = "chef-vendor-#{name_args[0]}" download = Chef::Knife::CookbookSiteDownload.new download.config[:file] = upstream_file download.name_args = name_args download.run - Dir.chdir(vendor_path) do - Chef::Log.info("Checking out the master branch") - system("git checkout master") - branch_output = `git branch --no-color | grep #{branch_name}` - if branch_output =~ /#{branch_name}$/m - system("git checkout #{branch_name}") + Chef::Log.info("Checking out the master branch.") + Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path) + Chef::Log.info("Checking the status of the vendor branch.") + status, branch_output, branch_error = Chef::Mixin::Command.output_of_command("git branch --no-color | grep #{branch_name}", :cwd => vendor_path) + if branch_output =~ /#{branch_name}$/m + Chef::Log.info("Vendor branch found.") + Chef::Mixin::Command.run_command(:command => "git checkout #{branch_name}", :cwd => vendor_path) + else + Chef::Log.info("Creating vendor branch.") + Chef::Mixin::Command.run_command(:command => "git checkout -b #{branch_name}", :cwd => vendor_path) + end + Chef::Log.info("Removing pre-existing version.") + Chef::Mixin::Command.run_command(:command => "rm -r #{cookbook_path}", :cwd => vendor_path) if File.directory?(cookbook_path) + Chef::Log.info("Uncompressing #{name_args[0]} version #{download.version}.") + Chef::Mixin::Command.run_command(:command => "tar zxvf #{upstream_file}", :cwd => vendor_path) + 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.") + 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::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path) + exit 1 + end + Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.") + Chef::Mixin::Command.run_command(:command => "git tag -f #{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 - system("git checkout -b #{branch_name}") + Chef::Log.error("You have merge conflicts - please resolve manually!") + Chef::Log.error("(Hint: cd #{vendor_path}; git status)") + exit 1 end - system("rm -r #{cookbook_path}") - system("tar zxvf #{upstream_file}") - system("rm #{upstream_file}") - system("git add #{name_args[0]}") - system("git commit -a -m 'Import #{name_args[0]} version #{download.version}'") - system("git tag -f #{name_args[0]}-#{download.version}") - system("git checkout master") - system("git merge #{branch_name}") end - Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored") end end |