Class: Capistrano::Deploy::SCM::Base

Class | Capistrano::Deploy::SCM::Base
In: | lib/capistrano/recipes/deploy/scm/base.rb lib/capistrano/recipes/deploy/scm/base.rb
Parent: | Object

The ancestor class for all Capistrano SCM implementations. It provides minimal infrastructure for subclasses to build upon and override.

Note that subclasses that implement this abstract class only return the commands that need to be executed—they do not execute the commands themselves. In this way, the deployment method may execute the commands either locally or remotely, as necessary.

### Methods

checkout checkout command command default_command default_command diff diff handle_data handle_data head head local local local? local? log log new new next_revision next_revision query_revision query_revision scm scm sync sync

### Classes and Modules

Class Capistrano::Deploy::SCM::Base::LocalProxy

### Attributes

configuration | [R] | The options available for this SCM instance to reference. Should be treated like a hash.
configuration | [R] | The options available for this SCM instance to reference. Should be treated like a hash.

### Public Class methods

default_command(value=nil)

If no parameters are given, it returns the current configured name of the command-line utility of this SCM. If a parameter is given, the defeault command is set to that value.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 17
    17:           def default_command(value=nil)
    18:             if value
    19:               @default_command = value
    20:             else
    21:               @default_command
    22:             end
    23:           end

default_command(value=nil)

If no parameters are given, it returns the current configured name of the command-line utility of this SCM. If a parameter is given, the defeault command is set to that value.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 17
    17:           def default_command(value=nil)
    18:             if value
    19:               @default_command = value
    20:             else
    21:               @default_command
    22:             end
    23:           end

new(configuration={})

Creates a new SCM instance with the given configuration options.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 44
    44:         def initialize(configuration={})
    45:           @configuration = configuration
    46:         end

new(configuration={})

Creates a new SCM instance with the given configuration options.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 44
    44:         def initialize(configuration={})
    45:           @configuration = configuration
    46:         end

### Public Instance methods

checkout(revision, destination)

Checkout a copy of the repository, at the given `revision`, to the given `destination`. The checkout is suitable for doing development work in, e.g. allowing subsequent commits and updates.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 87
    87:         def checkout(revision, destination)
    88:           raise NotImplementedError, "`checkout' is not implemented by #{self.class.name}"
    89:         end

checkout(revision, destination)

Checkout a copy of the repository, at the given `revision`, to the given `destination`. The checkout is suitable for doing development work in, e.g. allowing subsequent commits and updates.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 87
    87:         def checkout(revision, destination)
    88:           raise NotImplementedError, "`checkout' is not implemented by #{self.class.name}"
    89:         end

command()

Returns the name of the command-line utility for this SCM. It first looks at the :scm_command variable, and if it does not exist, it then falls back to whatever was defined by `default_command`.

If scm_command is set to :default, the default_command will be returned.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 147
    147:         def command
    148:           command = variable(:scm_command)
    149:           command = nil if command == :default
    150:           command || default_command
    151:         end

command()

Returns the name of the command-line utility for this SCM. It first looks at the :scm_command variable, and if it does not exist, it then falls back to whatever was defined by `default_command`.

If scm_command is set to :default, the default_command will be returned.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 147
    147:         def command
    148:           command = variable(:scm_command)
    149:           command = nil if command == :default
    150:           command || default_command
    151:         end

diff(from, to=nil)

Compute the difference between the two revisions, `from` and `to`.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 98
     98:         def diff(from, to=nil)
     99:           raise NotImplementedError, "`diff' is not implemented by #{self.class.name}"
    100:         end

diff(from, to=nil)

Compute the difference between the two revisions, `from` and `to`.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 98
     98:         def diff(from, to=nil)
     99:           raise NotImplementedError, "`diff' is not implemented by #{self.class.name}"
    100:         end

handle_data(state, stream, text)

Should analyze the given text and determine whether or not a response is expected, and if so, return the appropriate response. If no response is expected, return nil. The `state` parameter is a hash that may be used to preserve state between calls. This method is used to define how Capistrano should respond to common prompts and messages from the SCM, like password prompts and such. By default, the output is simply displayed.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 136
    136:         def handle_data(state, stream, text)
    137:           logger.info "[#{stream}] #{text}"
    138:           nil
    139:         end

handle_data(state, stream, text)

Should analyze the given text and determine whether or not a response is expected, and if so, return the appropriate response. If no response is expected, return nil. The `state` parameter is a hash that may be used to preserve state between calls. This method is used to define how Capistrano should respond to common prompts and messages from the SCM, like password prompts and such. By default, the output is simply displayed.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 136
    136:         def handle_data(state, stream, text)
    137:           logger.info "[#{stream}] #{text}"
    138:           nil
    139:         end

head()

Returns the string used to identify the latest revision in the repository. This will be passed as the "revision" parameter of the methods below.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 80
    80:         def head
    81:           raise NotImplementedError, "`head' is not implemented by #{self.class.name}"
    82:         end

head()

Returns the string used to identify the latest revision in the repository. This will be passed as the "revision" parameter of the methods below.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 80
    80:         def head
    81:           raise NotImplementedError, "`head' is not implemented by #{self.class.name}"
    82:         end

local() {|| ...}

Returns a proxy that wraps the SCM instance and forces it to operate in "local" mode, which changes how variables are looked up in the configuration. Normally, if the value of a variable "foo" is needed, it is queried for in the configuration as "foo". However, in "local" mode, first "local_foo" would be looked for, and only if it is not found would "foo" be used. This allows for both (e.g.) "scm_command" and "local_scm_command" to be set, if the two differ.

Alternatively, it may be called with a block, and for the duration of the block, all requests on this configuration object will be considered local.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 59
    59:         def local
    60:           if block_given?
    61:             begin
    62:               saved, @local_mode = @local_mode, true
    63:               yield
    64:             ensure
    65:               @local_mode = saved
    66:             end
    67:           else
    68:             LocalProxy.new(self)
    69:           end
    70:         end

local() {|| ...}

Returns a proxy that wraps the SCM instance and forces it to operate in "local" mode, which changes how variables are looked up in the configuration. Normally, if the value of a variable "foo" is needed, it is queried for in the configuration as "foo". However, in "local" mode, first "local_foo" would be looked for, and only if it is not found would "foo" be used. This allows for both (e.g.) "scm_command" and "local_scm_command" to be set, if the two differ.

Alternatively, it may be called with a block, and for the duration of the block, all requests on this configuration object will be considered local.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 59
    59:         def local
    60:           if block_given?
    61:             begin
    62:               saved, @local_mode = @local_mode, true
    63:               yield
    64:             ensure
    65:               @local_mode = saved
    66:             end
    67:           else
    68:             LocalProxy.new(self)
    69:           end
    70:         end

local?()

Returns true if running in "local" mode. See local.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 73
    73:         def local?
    74:           @local_mode
    75:         end

local?()

Returns true if running in "local" mode. See local.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 73
    73:         def local?
    74:           @local_mode
    75:         end

log(from, to=nil)

Return a log of all changes between the two specified revisions, `from` and `to`, inclusive.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 104
    104:         def log(from, to=nil)
    105:           raise NotImplementedError, "`log' is not implemented by #{self.class.name}"
    106:         end

log(from, to=nil)

Return a log of all changes between the two specified revisions, `from` and `to`, inclusive.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 104
    104:         def log(from, to=nil)
    105:           raise NotImplementedError, "`log' is not implemented by #{self.class.name}"
    106:         end

next_revision(revision)

Returns the revision number immediately following revision, if at all possible. A block should always be passed to this method, which accepts a command to invoke and returns the result, although a particular SCM‘s implementation is not required to invoke the block.

By default, this method simply returns the revision itself. If a particular SCM is able to determine a subsequent revision given a revision identifier, it should override this method.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 125
    125:         def next_revision(revision)
    126:           revision
    127:         end

next_revision(revision)

Returns the revision number immediately following revision, if at all possible. A block should always be passed to this method, which accepts a command to invoke and returns the result, although a particular SCM‘s implementation is not required to invoke the block.

By default, this method simply returns the revision itself. If a particular SCM is able to determine a subsequent revision given a revision identifier, it should override this method.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 125
    125:         def next_revision(revision)
    126:           revision
    127:         end

query_revision(revision)

If the given revision represents a "real" revision, this should simply return the revision value. If it represends a pseudo-revision (like Subversions "HEAD" identifier), it should yield a string containing the commands that, when executed will return a string that this method can then extract the real revision from.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 113
    113:         def query_revision(revision)
    114:           raise NotImplementedError, "`query_revision' is not implemented by #{self.class.name}"
    115:         end

query_revision(revision)

If the given revision represents a "real" revision, this should simply return the revision value. If it represends a pseudo-revision (like Subversions "HEAD" identifier), it should yield a string containing the commands that, when executed will return a string that this method can then extract the real revision from.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 113
    113:         def query_revision(revision)
    114:           raise NotImplementedError, "`query_revision' is not implemented by #{self.class.name}"
    115:         end

scm(*args)

A helper method that can be used to define SCM commands naturally. It returns a single string with all arguments joined by spaces, with the scm command prefixed onto it.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 156
    156:         def scm(*args)
    157:           [command, *args].compact.join(" ")
    158:         end

scm(*args)

A helper method that can be used to define SCM commands naturally. It returns a single string with all arguments joined by spaces, with the scm command prefixed onto it.

[Source]

         # File lib/capistrano/recipes/deploy/scm/base.rb, line 156
    156:         def scm(*args)
    157:           [command, *args].compact.join(" ")
    158:         end

sync(revision, destination)

Resynchronize the working copy in `destination` to the specified `revision`.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 93
    93:         def sync(revision, destination)
    94:           raise NotImplementedError, "`sync' is not implemented by #{self.class.name}"
    95:         end

sync(revision, destination)

Resynchronize the working copy in `destination` to the specified `revision`.

[Source]

        # File lib/capistrano/recipes/deploy/scm/base.rb, line 93
    93:         def sync(revision, destination)
    94:           raise NotImplementedError, "`sync' is not implemented by #{self.class.name}"
    95:         end

[Validate]