class Capistrano::Deploy::SCM::GitLocal

An SCM that works in tandem with the :remote_cache_from_local strategy to support git submodules being retrieved via the local SSH tunnel also. Does not currently support recursive submodules.

Public Instance Methods

checkout(revision, destination) click to toggle source
Calls superclass method
# File lib/capistrano/recipes/deploy/scm/git_local.rb, line 11
def checkout(revision, destination)
  super_command = super
  super_with_submodules_if_enabled(super_command, destination)
end
sync(revision, destination) click to toggle source
Calls superclass method
# File lib/capistrano/recipes/deploy/scm/git_local.rb, line 16
def sync(revision, destination)
  sync_command = super
  # Match remote URL to current repository setting — don't know why the base
  # Git SCM only does this when the remote is not "origin".
  sync_with_remote_set_url_command = [
    "cd #{destination}",
    "#{command} remote set-url #{origin} #{variable(:repository)}",
    sync_command
  ].join(' && ')

  super_with_submodules_if_enabled(sync_with_remote_set_url_command, destination)
end

Private Instance Methods

super_with_submodules_if_enabled(super_command, destination) click to toggle source
# File lib/capistrano/recipes/deploy/scm/git_local.rb, line 31
def super_with_submodules_if_enabled(super_command, destination)
  if variable(:git_local_enable_submodules)
    [super_command, update_submodules(destination)].join(' && ')
  else
    super_command
  end
end
update_submodules(main_checkout) click to toggle source
# File lib/capistrano/recipes/deploy/scm/git_local.rb, line 39
def update_submodules(main_checkout)
  git = command
  repo_prefix = repository.sub(/\.git$/, '')
  execute = []

  submodules_root = File.expand_path('../cached-submodules', main_checkout)
  execute << "mkdir -p #{submodules_root}"
  execute << "cd #{main_checkout}"
  execute << "#{git} submodule #{verbose} init"
  # This mess does the following:
  # - Parses .gitmodules to extract a list of [path-property-name, path-value] pairs
  # - For each of these pairs,
  #   - Transforms the path property name to the URL property name
  #   - Uses git-config to set the local URL property of the submodule to the version available via the SSH tunnel
  # N.b.: `git submodule foreach` could do this slightly cleaner, but it doesn't work until after `update` for some reason.
  execute << %Q[#{git} config -f .gitmodules --get-regexp 'submodule.*path' | awk '{ gsub("path", "url", $1); system(sprintf("git config %s #{repo_prefix}%s/.git", $1, $2)) }']
  execute << "#{git} config --get-regexp submodule" if variable(:scm_verbose)
  execute << "#{git} submodule #{verbose} update"

  execute.join(' && ')
end