|
17 | 17 | # |
18 | 18 |
|
19 | 19 | require'chef/knife' |
| 20 | +require'chef/cookbook/metadata' |
20 | 21 |
|
21 | 22 | classChef |
22 | 23 | classKnife |
23 | 24 | classCookbookSiteVendor < Knife |
24 | 25 |
|
25 | 26 | banner"Sub-Command: cookbook site vendor COOKBOOK [VERSION] (options)" |
26 | 27 |
|
| 28 | +option:deps, |
| 29 | +:short=>"-d", |
| 30 | +:long=>"--dependencies", |
| 31 | +:boolean=>true, |
| 32 | +:description=>"Grab dependencies automatically" |
| 33 | + |
27 | 34 | defrun |
28 | 35 | vendor_path=File.join(Chef::Config[:cookbook_path].first) |
29 | 36 | cookbook_path=File.join(vendor_path,name_args[0]) |
@@ -53,29 +60,45 @@ def run |
53 | 60 | Chef::Mixin::Command.run_command(:command=>"rm #{upstream_file}",:cwd=>vendor_path) |
54 | 61 | Chef::Log.info("Adding changes.") |
55 | 62 | Chef::Mixin::Command.run_command(:command=>"git add #{name_args[0]}",:cwd=>vendor_path) |
| 63 | + |
56 | 64 | Chef::Log.info("Committing changes.") |
| 65 | +changes=true |
57 | 66 | begin |
58 | 67 | Chef::Mixin::Command.run_command(:command=>"git commit -a -m 'Import #{name_args[0]} version #{download.version}'",:cwd=>vendor_path) |
59 | 68 | rescueChef::Exceptions::Exec=>e |
60 | 69 | Chef::Log.warn("Checking out the master branch.") |
61 | | -Chef::Log.warn("No changes from current vendor #{name_args[0]}, aborting!") |
| 70 | +Chef::Log.warn("No changes from current vendor #{name_args[0]}") |
62 | 71 | Chef::Mixin::Command.run_command(:command=>"git checkout master",:cwd=>vendor_path) |
63 | | -exit1 |
| 72 | +changes=false |
64 | 73 | end |
65 | | -Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.") |
66 | | -Chef::Mixin::Command.run_command(:command=>"git tag -f chef-vendor-#{name_args[0]}-#{download.version}",:cwd=>vendor_path) |
67 | | -Chef::Log.info("Checking out the master branch.") |
68 | | -Chef::Mixin::Command.run_command(:command=>"git checkout master",:cwd=>vendor_path) |
69 | | -Chef::Log.info("Merging changes from #{name_args[0]} version #{download.version}.") |
70 | | - |
71 | | -Dir.chdir(vendor_path)do |
72 | | -ifsystem("git merge #{branch_name}") |
73 | | -Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!") |
74 | | -exit0 |
75 | | -else |
76 | | -Chef::Log.error("You have merge conflicts - please resolve manually!") |
77 | | -Chef::Log.error("(Hint: cd #{vendor_path}; git status)") |
78 | | -exit1 |
| 74 | + |
| 75 | +ifchanges |
| 76 | +Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.") |
| 77 | +Chef::Mixin::Command.run_command(:command=>"git tag -f chef-vendor-#{name_args[0]}-#{download.version}",:cwd=>vendor_path) |
| 78 | +Chef::Log.info("Checking out the master branch.") |
| 79 | +Chef::Mixin::Command.run_command(:command=>"git checkout master",:cwd=>vendor_path) |
| 80 | +Chef::Log.info("Merging changes from #{name_args[0]} version #{download.version}.") |
| 81 | + |
| 82 | +Dir.chdir(vendor_path)do |
| 83 | +ifsystem("git merge #{branch_name}") |
| 84 | +Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!") |
| 85 | +else |
| 86 | +Chef::Log.error("You have merge conflicts - please resolve manually!") |
| 87 | +Chef::Log.error("(Hint: cd #{vendor_path}; git status)") |
| 88 | +exit1 |
| 89 | +end |
| 90 | +end |
| 91 | +end |
| 92 | + |
| 93 | +ifconfig[:deps] |
| 94 | +md=Chef::Cookbook::Metadata.new |
| 95 | +md.from_file(File.join(cookbook_path,"metadata.rb")) |
| 96 | +md.dependencies.eachdo |cookbook,version_list| |
| 97 | +# Doesn't do versions.. yet |
| 98 | +nv=Chef::Knife::CookbookSiteVendor.new |
| 99 | +nv.config=config |
| 100 | +nv.name_args=[cookbook] |
| 101 | +nv.run |
79 | 102 | end |
80 | 103 | end |
81 | 104 | end |
|
0 commit comments