Class: Capistrano::Distribution::Distributor::GitPull

Inherits:
AbstractGit show all
Defined in:
lib/capistrano/distribution/distributor/git_pull.rb

Overview

Distributes by mirroring a remote Git repository on each target host and then extracting the content from a revision to the release location.

Instance Attribute Summary

Attributes inherited from AbstractGit

#revision, #subtree

Attributes inherited from Abstract

#context, #repo_id, #target, #url

Instance Method Summary collapse

Methods inherited from AbstractGit

#initialize, #release

Methods inherited from Abstract

#initialize, #release_path, #repo_path

Constructor Details

This class inherits a constructor from Capistrano::Distribution::Distributor::AbstractGit

Instance Method Details

#checkBoolean

Tests that the Git repository at Abstract#url is readable.

Returns:

  • (Boolean)

    true if the repository is readable; otherwise, false



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

def check
  context.test 'git', 'ls-remote', url
end

#clonenil (private)

Creates a mirror of the repository at Abstract#url in Abstract#repo_path if it does not already exist.

Returns:

  • (nil)

Raises:

  • (exception)

    when mirror creation fails.



43
44
45
46
47
48
49
# File 'lib/capistrano/distribution/distributor/git_pull.rb', line 43

def clone
  if context.test '[', '!', '-e', repo_path.join('HEAD'), ']'
    context.execute 'rm', '-rf', repo_path
    context.execute 'git', 'clone', '--mirror', url, repo_path
  end
  nil
end

#distributenil

Creates a mirror of the Git repository at Abstract#url if necessary, pulls updates into it, and finally extracts the revision to the release area. The Git repository is left in place in order to speed up future deployments by avoiding the need to pull all revision history again.

Returns:

  • (nil)

Raises:

  • (exception)

    when distribution fails.



28
29
30
31
32
# File 'lib/capistrano/distribution/distributor/git_pull.rb', line 28

def distribute
  clone
  update
  release
end

#updatenil (private)

Updates the Git mirror.

Returns:

  • (nil)

Raises:

  • (exception)

    when updating the mirror fails.



57
58
59
60
61
62
# File 'lib/capistrano/distribution/distributor/git_pull.rb', line 57

def update
  context.execute 'git', '--git-dir', repo_path,
                  'remote', 'set-url', 'origin', url
  context.execute 'git', '--git-dir', repo_path, 'remote', 'update', '--prune'
  nil
end