根据this recent thread,capistrano 应该能够初始化和更新您的子模块:
set :git_enable_submodules,1
如果您的 .gitmodules 条目是最新的,则在 config/deploy.rb 中应该足够了。
您可能需要to patch Capistrano (lib/capistano/recipes/deploy/scm/git.rb) 来确保您的子模块被包含在内。
def checkout(revision, destination)
git = command
branch = head
fail "No branch specified, use for example 'set :branch, \"origin/master\"' in your deploy.rb" unless branch
if depth = configuration[:git_shallow_clone]
execute = "#{git} clone --depth #{depth} #{configuration[:repository]} #{destination} && "
else
execute = "#{git} clone #{configuration[:repository]} #{destination} && "
end
execute += "cd #{destination} && #{git} checkout -b deploy #{branch}"
if submodules = configuration[:git_enable_submodules]
execute += " && git-submodule init &&"
execute += "git-submodule update"
end
execute
end
如果你有nested submodules,你需要:
gem sources -a http://gems.github.com
$ sudo gem install morhekil-capistrano-deepmodules
只需在您的部署配置中使用它:
需要'capistrano/deepmodules'
gem 会自动处理所有其余的事情。
你可以从你的配置中删除:git_enable_submodules,gem 不会注意它——如果你需要它,你已经在说你想要启用子模块。
还有一个需要注意的细节 - 目前 gem 只支持远程缓存策略。这意味着您必须在您的 config 中添加以下行:
set :deploy_via, :remote_cache
它启用了远程缓存,这确实是您想要做的事情 - 如果您没有服务器端缓存,那么部署包含大量子模块和其他东西的大型代码库确实是一种麻烦的体验。