Class: Capistrano::Distribution::Distributor::AbstractGit Abstract

Inherits:
Abstract
  • Object
show all
Defined in:
lib/capistrano/distribution/distributor/abstract_git.rb

Overview

This class is abstract.

Subclass and override Capistrano::Distribution::Distributor::Abstract#check and Capistrano::Distribution::Distributor::Abstract#distribute to create a distributor that uses Git to distribute code from a Git repository.

An abstract distributor that operates on Git repositories.

Direct Known Subclasses

GitPull, GitPush

Instance Attribute Summary collapse

Attributes inherited from Abstract

#context, #repo_id, #target, #url

Instance Method Summary collapse

Methods inherited from Abstract

#check, #distribute, #release_path, #repo_path

Constructor Details

#initialize(context, url, revision, opts = {}) ⇒ AbstractGit

Returns a new instance of AbstractGit.

Parameters:

  • url (URI, String)

    a URL to be used for fetching the artifact to be distributed

  • revision (String)

    a commit identifier (revision SHA or ref) to be distributed



22
23
24
25
26
# File 'lib/capistrano/distribution/distributor/abstract_git.rb', line 22

def initialize(context, url, revision, opts = {})
  super(context, url, opts)
  @revision = revision
  @subtree = opts[:subtree]
end

Instance Attribute Details

#revisionObject (readonly)

The identifier for a Git commit that will be distributed.



15
16
17
# File 'lib/capistrano/distribution/distributor/abstract_git.rb', line 15

def revision
  @revision
end

#subtreeObject (readonly, private)

A subtree of the repository to distribute.



32
33
34
# File 'lib/capistrano/distribution/distributor/abstract_git.rb', line 32

def subtree
  @subtree
end

Instance Method Details

#releasenil (private)

Extracts the content of the commit at #revision from the local mirror of the repository to Capistrano::Distribution::Distributor::Abstract#release_path.

Returns:

  • (nil)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/capistrano/distribution/distributor/abstract_git.rb', line 39

def release
  context.execute 'mkdir', '-p', release_path

  if subtree
    path = subtree.slice %r#^/?(.*?)/?$#, 1
    components = path.split('/').size
    context.execute :git, '--git-dir', repo_path, :archive, revision, path, "| tar -x --strip-components #{components} -f - -C", release_path
  else
    context.execute :git, '--git-dir', repo_path, :archive, revision, '| tar -x -f - -C', release_path
  end

  nil
end