Created
January 2, 2009 19:30
-
-
Save revans/42641 to your computer and use it in GitHub Desktop.
Managing Git Submodules in Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is used for updating all of our Submodules | |
# PLUGINS | |
# | |
# ==== Description | |
# | |
# Define your rails plugins here to be managed by git submodules. | |
# | |
# | |
@plugins = { | |
# :taggable => "acts_as_taggable_redux", | |
:asset_packer => "asset_packager", | |
:exception => "exception_notification", | |
# :openid => "open_id_authentication", | |
:paginate => "will_paginate", | |
:paperclip => "paperclip", | |
:geokit => "geokit", | |
:rspec => "rspec", | |
:rspec_rails => "rspec_rails", | |
:ssl_requirement => "ssl_requirement", | |
:cucumber => "cucumber", | |
:active_merchant => "active_merchant" | |
} | |
namespace :git do | |
namespace :submodule do | |
desc "When checking out the project, you're gonna need to init the submodules and then update them." | |
task :update do | |
system('git submodule init') | |
system('git submodule update') | |
end | |
desc "Remove a submodule" | |
task :remove, :submodule do |task, args| | |
git_remove(args.submodule) | |
end | |
end | |
namespace :update do | |
# | |
# ==== Description | |
# | |
# Iterate through the PLUGINS hash so that each plugin | |
# can show up as a rake task when doing rake -T | |
# | |
# | |
@plugins.each do |type, file| | |
desc "Update #{type.to_s} git submodule" | |
task type do | |
git_update(file) | |
end | |
end | |
# Update All Git Submodules | |
# | |
# ==== Description | |
# | |
# This will iterate through our plugins hash and update everything in | |
# the hash. | |
# | |
# | |
desc "Update all git submodules" | |
task :all do | |
@plugins.each do |type, file| | |
puts "\nUPDATING & MERGING: #{type.to_s.upcase} Plugin via Git Submodule" | |
puts "----------------------------------------------------------------\n" | |
git_update(file) | |
puts "----------------------------------------------------------------\n" | |
end | |
puts "\nUPDATING & MERGING: RAILS via Git Submodule" | |
puts "----------------------------------------------------------------\n" | |
Rake::Task['git:update:rails'].invoke | |
puts "----------------------------------------------------------------\n" | |
end | |
# Rails | |
# | |
# ==== Description | |
# | |
# Update Rails to the latest Edge Version | |
# | |
# | |
desc "Update Rails to the latest Edge Version" | |
task :rails do | |
git_update | |
end | |
end | |
end | |
# Git Update | |
# | |
# ==== Description | |
# | |
# This accepts a type, which should be a symbol, and then yields itself | |
# so that the file name of the plugin or rails can be defined. | |
# It then runs a system command and cd's the specified directory and | |
# does a git remote update to pull down the latest version of the plugin | |
# or rails itself and then merges it with the master. | |
# | |
# | |
def git_update(name = nil) | |
dir = name.nil? ? "vendor/rails/" : "vendor/plugins/#{name}" | |
system("cd #{dir} && git remote update && git merge origin/master") | |
end | |
# Git Remove | |
# | |
# ==== Description | |
# | |
# This will remove a git submodule from the cache. | |
# | |
# | |
def git_remove(submodule) | |
system("git rm --cached vendor/plugins/#{submodule}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment