Skip to content

Instantly share code, notes, and snippets.

@cyu
Forked from stevenscg/submodule_strategy.rb
Created July 5, 2019 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyu/fec0daed90cfeaf1495916f68955cc81 to your computer and use it in GitHub Desktop.
Save cyu/fec0daed90cfeaf1495916f68955cc81 to your computer and use it in GitHub Desktop.
Capistrano deploy strategy that supports git submodules (requires Capistrano v3.1.0 or later)
# this include won't work for some reason:
# include Capistrano::Git::DefaultStrategy
module SubmoduleStrategy
# check for a .git directory
def test
test! " [ -d #{repo_path}/.git ] "
end
# same as in Capistrano::Git::DefaultStrategy
def check
test! :git, :'ls-remote', repo_url
end
def clone
git :clone, '-b', fetch(:branch), '--recursive', repo_url, repo_path
end
# same as in Capistrano::Git::DefaultStrategy
def update
git :remote, :update
end
# put the working tree in a release-branch,
# make sure the submodules are up-to-date
# and copy everything to the release path
def release
release_branch = fetch(:release_branch, File.basename(release_path))
git :checkout, '-b', release_branch, fetch(:remote_branch, "origin/#{fetch(:branch)}")
git :submodule, :update, '--init'
context.execute "rsync -ar --exclude=.git\* #{repo_path}/ #{release_path}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment