Class: Capistrano::Distribution::Distributor::GitPush

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

Overview

Distributes by pushing a local Git repository into a clone 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

#checktrue

Always returns true because this distributor does not pull content but rather relies on the distribute step to push the content up.

Returns:

  • (true)


16
17
18
# File 'lib/capistrano/distribution/distributor/git_push.rb', line 16

def check
  true
end

#distributenil

Prepares a Git repository if necessary, pushes the selected revision to the Git repository, 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 upload all revision history again.

Returns:

  • (nil)

Raises:

  • (exception)

    when distribution fails.



29
30
31
32
33
34
# File 'lib/capistrano/distribution/distributor/git_push.rb', line 29

def distribute
  init
  push
  release
  nil
end

#initnil (private)

Initializes a bare Git repository in Abstract#repo_path if a repository does not already exist there.

Returns:

  • (nil)

Raises:

  • (exception)

    when repository creation fails.



45
46
47
48
49
50
51
# File 'lib/capistrano/distribution/distributor/git_push.rb', line 45

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

#pushObject (private)

Pushes AbstractGit#revision and all its history to the Git repository within Abstract#repo_path.

Raises:

  • (exception)

    when the push to the repository fails.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/capistrano/distribution/distributor/git_push.rb', line 58

def push
  user = context.host.user
  hostname = context.host.hostname
  repo_path = self.repo_path
  revision = self.revision
  context.run_locally do
    execute 'git', 'push',
            "ssh://#{user}@#{hostname}/#{repo_path}",
            "+#{revision}:refs/tags/deploy"
  end
end