Skip to content

Instantly share code, notes, and snippets.

@dysinger
Created November 24, 2009 02:29
Show Gist options
  • Select an option

  • Save dysinger/241579 to your computer and use it in GitHub Desktop.

Select an option

Save dysinger/241579 to your computer and use it in GitHub Desktop.
namespace(:cookbooks) do
#
# This rake script enables merging in public "cookbooks" from
# opscode into your local "chef-repo"
#
# generating per-cookbook branches takes a while. run this task on
# your opscode cookbooks git clone and you'll end up with a zillion
# branches with one cookbook per branch
#
# if you like just skip to "option #2" below to play around with this.
#
desc "make per-cookbook branches from the opscode cookbook repository"
task(:branch) do
Dir.glob("*").select {|x| FileTest.directory?(x) }.each do |path|
`git checkout master`
`git branch -D #{path}`
`git checkout -b #{path}`
`git filter-branch --tree-filter \
'rm -rf .gitignore #{Dir.glob("*").reject {|x| x == path}.join(" ")}' \
--prune-empty HEAD`
`rm -rf .git/refs/original`
`git reset --hard HEAD`
`git push -f origin #{path}`
end
`git checkout master`
`git gc --aggressive`
`git prune`
end
# now go into your local "chef-repo" project.
#
# option #1
# if you ran the branch-producing script above and "cookbooks" is
# local do something like:
# git remote add cookbooks ../cookbooks
#
# option #2
# if you just want to play around with my repo add this
# git remote add cookbooks git://github.com/dysinger/cookbooks.git
# now merge in an opscode cookbook right into your chef-repo without
# loosing the history and enabling future pulls
# (when opscode updates the cookbook) upstream :)
# lets try it:
#
# git remote fetch cookbooks
# rake -f ~/.rake/cookbooks.rake cookbooks:add[openvpn]
#
# now go see your new imported cookbooks/openvpn in a branch
# complete with commit history. :)
#
desc "add an opscode cookbook as a branch in this chef repo"
task(:add, :cookbook) do |_,a|
`git checkout -b #{a.cookbook} master`
`git merge -s ours --no-commit cookbooks/#{a.cookbook}`
`git read-tree --prefix=cookbooks/ -u cookbooks/#{a.cookbook}`
`git commit -m "Merge cookbooks/#{a.cookbook}"`
end
# ok you have updated from opscode and recreated the branches and
# need to pull updates for your branch again.
#
# rake -f ~/.rake/cookbooks.rake cookbooks:update[openvpn]
#
desc "pull an opscode cookbook's updates into our branch"
task(:update, :cookbook) do |_,a|
`git checkout #{a.cookbook} && \
git pull -s subtree cookbooks #{a.cookbook}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment