Skip to content
Browse files

Merge branch 'CHEF-2013'

  • Loading branch information...
2 parents 5f42d48 + 9f16c12 commit 4f100fd2c2bd98c964fd0711618e2ed46c087cc3 @btm btm committed Feb 4, 2011
Showing with 17 additions and 11 deletions.
  1. +17 −11 chef/lib/chef/knife/cookbook_site_vendor.rb
View
28 chef/lib/chef/knife/cookbook_site_vendor.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,6 +38,12 @@ class CookbookSiteVendor < Knife
:description => "A colon-separated path to look for cookbooks in",
:proc => lambda { |o| o.split(":") }
+ option :branch_default,
+ :short => "-B BRANCH",
+ :long => "--branch BRANCH",
+ :description => "Default branch to work with",
+ :default => "master"
+
def run
if config[:cookbook_path]
Chef::Config[:cookbook_path] = config[:cookbook_path]
@@ -57,14 +63,14 @@ def run
branch_name = "chef-vendor-#{name_args[0]}"
download = Chef::Knife::CookbookSiteDownload.new
- download.config[:file] = upstream_file
+ download.config[:file] = upstream_file
download.name_args = name_args
download.run
- Chef::Log.info("Checking out the master branch.")
- Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
+ Chef::Log.info("Checking out the #{config[:branch_default]} branch.")
+ Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :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)
+ status, branch_output, branch_error = Chef::Mixin::Command.output_of_command("git branch --no-color | grep #{branch_name}", :cwd => vendor_path)
if branch_output =~ /#{Regexp.escape(branch_name)}$/m
Chef::Log.info("Vendor branch found.")
Chef::Mixin::Command.run_command(:command => "git checkout #{branch_name}", :cwd => vendor_path)
@@ -85,25 +91,25 @@ def run
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("Checking out the #{config[:branch_default]} branch.")
Chef::Log.warn("No changes from current vendor #{name_args[0]}")
- Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
+ Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
changes = false
end
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("Checking out the #{config[:branch_default]} branch.")
+ Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :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)")
+ Chef::Log.error("(Hint: cd #{vendor_path}; git status)")
exit 1
end
end

0 comments on commit 4f100fd

Please sign in to comment.
Something went wrong with that request. Please try again.