class Capistrano::Distribution::Distributor::GitPush

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.

Public Instance Methods

check() click to toggle source

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

@return [true]

# File lib/capistrano/distribution/distributor/git_push.rb, line 16
def check
  true
end
distribute() click to toggle source

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.

@return [nil]

@raise [exception] when distribution fails.

# File lib/capistrano/distribution/distributor/git_push.rb, line 29
def distribute
  init
  push
  release
  nil
end

Private Instance Methods

init() click to toggle source

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

@return [nil]

@raise [exception] when repository creation fails.

# 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
push() click to toggle source

Pushes {#revision} and all its history to the Git repository within {#repo_path}.

@raise [exception] when the push to the repository fails.

# 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