Skip to content

Commit 73dab4a

Browse files
committed
Adding dependency support for vendoring
1 parent 0986502 commit 73dab4a

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

‎chef/lib/chef/knife/cookbook_site_vendor.rb‎

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@
1717
#
1818

1919
require'chef/knife'
20+
require'chef/cookbook/metadata'
2021

2122
classChef
2223
classKnife
2324
classCookbookSiteVendor < Knife
2425

2526
banner"Sub-Command: cookbook site vendor COOKBOOK [VERSION] (options)"
2627

28+
option:deps,
29+
:short=>"-d",
30+
:long=>"--dependencies",
31+
:boolean=>true,
32+
:description=>"Grab dependencies automatically"
33+
2734
defrun
2835
vendor_path=File.join(Chef::Config[:cookbook_path].first)
2936
cookbook_path=File.join(vendor_path,name_args[0])
@@ -53,29 +60,45 @@ def run
5360
Chef::Mixin::Command.run_command(:command=>"rm #{upstream_file}",:cwd=>vendor_path)
5461
Chef::Log.info("Adding changes.")
5562
Chef::Mixin::Command.run_command(:command=>"git add #{name_args[0]}",:cwd=>vendor_path)
63+
5664
Chef::Log.info("Committing changes.")
65+
changes=true
5766
begin
5867
Chef::Mixin::Command.run_command(:command=>"git commit -a -m 'Import #{name_args[0]} version #{download.version}'",:cwd=>vendor_path)
5968
rescueChef::Exceptions::Exec=>e
6069
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]}")
6271
Chef::Mixin::Command.run_command(:command=>"git checkout master",:cwd=>vendor_path)
63-
exit1
72+
changes=false
6473
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
79102
end
80103
end
81104
end

0 commit comments

Comments
(0)