-
-
Save jjasghar/d9369c60c51f79d6e7cc to your computer and use it in GitHub Desktop.
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
# Usage: | |
# 1. Drop this file into lib/capistrano/submodule_strategy.rb | |
# 2. Add the following to your Capfile: | |
# require 'capistrano/git' | |
# require './lib/capistrano/submodule_strategy' | |
# 3. Add the following to your config/deploy.rb | |
# set :git_strategy, SubmoduleStrategy | |
# 4. Add .capignore file and list each file or directory to exclude from deployment on a separate line. Example: | |
# .capignore | |
# lib | |
# config | |
# .git | |
module SubmoduleStrategy | |
# do all the things a normal capistrano git session would do | |
include Capistrano::Git::DefaultStrategy | |
# 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-from '#{repo_path}/.capignore' #{repo_path}/ #{release_path}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You've referenced this in a blog post. http://jjasghar.github.io/blog/2014/06/04/moving-to-capistrano-version-3-from-version-2/