class Capistrano::Configuration::SCMResolver

In earlier versions of Capistrano, users would specify the desired SCM implementation using ‘set :scm, :git`, for example. Capistrano would then load the matching .rb file based on this variable.

Now we expect users to explicitly ‘require` and call `new` on the desired SCM implementation in their Capfile. The `set` technique is deprecated.

This SCMResolver class takes care of managing the transition from the old to new system. It maintains the legacy behavior, but prints deprecation warnings when it is used.

To maintain backwards compatibility, the resolver will load the Git SCM by if default it determines that no SCM has been explicitly specified or loaded. To force no SCM to be used at all, use ‘set :scm, nil`. This hack won’t be necessary once backwards compatibility is removed in a future version.

TODO: Remove this class entirely in Capistrano 4.0.

Constants

DEFAULT_GIT

Public Instance Methods

resolve() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 27
def resolve
  return if scm_name.nil?
  set(:scm, :git) if using_default_scm?

  print_deprecation_warnings_if_applicable

  # Note that `scm_plugin_installed?` comes from Capistrano::DSL
  if scm_plugin_installed?
    delete(:scm)
    return
  end

  if built_in_scm_name?
    load_built_in_scm
  else
    # Compatibility with existing 3.x third-party SCMs
    register_legacy_scm_hooks
    load_legacy_scm_by_name
  end
end

Private Instance Methods

built_in_scm_name?() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 76
def built_in_scm_name?
  %w(git hg svn).include?(scm_name.to_s.downcase)
end
built_in_scm_plugin_class_name() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 80
def built_in_scm_plugin_class_name
  "Capistrano::SCM::#{scm_name.to_s.capitalize}"
end
load_built_in_scm() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 59
def load_built_in_scm
  require "capistrano/scm/#{scm_name}"
  scm_class = Object.const_get(built_in_scm_plugin_class_name)
  # We use :load_immediately because we are initializing the SCM plugin
  # late in the load process and therefore can't use the standard
  # load:defaults technique.
  install_plugin(scm_class, load_immediately: true)
end
load_legacy_scm_by_name() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 68
def load_legacy_scm_by_name
  load("capistrano/#{scm_name}.rb")
end
print_deprecation_warnings_if_applicable() click to toggle source

rubocop:enable Style/GuardClause

register_legacy_scm_hooks() click to toggle source

rubocop:disable Style/GuardClause

# File lib/capistrano/configuration/scm_resolver.rb, line 85
def register_legacy_scm_hooks
  if Rake::Task.task_defined?("deploy:new_release_path")
    after "deploy:new_release_path", "#{scm_name}:create_release"
  end

  if Rake::Task.task_defined?("deploy:check")
    before "deploy:check", "#{scm_name}:check"
  end

  if Rake::Task.task_defined?("deploy:set_current_revision")
    before "deploy:set_current_revision",
           "#{scm_name}:set_current_revision"
  end
end
scm_name() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 55
def scm_name
  fetch(:scm)
end
third_party_scm_name?() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 72
def third_party_scm_name?
  !built_in_scm_name?
end
using_default_scm?() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 50
def using_default_scm?
  return @using_default_scm if defined? @using_default_scm
  @using_default_scm = (fetch(:scm) == DEFAULT_GIT)
end
warn_add_git_to_capfile() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 124
      def warn_add_git_to_capfile
        $stderr.puts(<<-MESSAGE)
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning, add the following to
your Capfile after `require "capistrano/deploy"`:

    require "capistrano/scm/git"
    install_plugin Capistrano::SCM::Git

MESSAGE
      end
warn_set_scm_is_deprecated() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 111
      def warn_set_scm_is_deprecated
        $stderr.puts(<<-MESSAGE)
[Deprecation Notice] `set :scm, #{scm_name.inspect}` is deprecated.
To ensure your project is compatible with future versions of Capistrano,
remove the :scm setting and instead add these lines to your Capfile after
`require "capistrano/deploy"`:

    require "capistrano/scm/#{scm_name}"
    install_plugin #{built_in_scm_plugin_class_name}

MESSAGE
      end
warn_third_party_scm_must_be_upgraded() click to toggle source
# File lib/capistrano/configuration/scm_resolver.rb, line 136
      def warn_third_party_scm_must_be_upgraded
        $stderr.puts(<<-MESSAGE)
[Deprecation Notice] `set :scm, #{scm_name.inspect}` is deprecated.
To ensure this custom SCM will work with future versions of Capistrano,
please upgrade it to a version that uses the new SCM plugin mechanism
documented here:

http://capistranorb.com/documentation/advanced-features/custom-scm

MESSAGE
      end