Class: Capistrano::Git::Copy::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/git/copy/utility.rb

Overview

Utility stuff to avoid cluttering of deploy.cap

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Utility



9
10
11
# File 'lib/capistrano/git/copy/utility.rb', line 9

def initialize(context)
  @context = context
end

Instance Method Details

#archive_pathString

Path to archive



106
107
108
# File 'lib/capistrano/git/copy/utility.rb', line 106

def archive_path
  @_archive_path ||= File.join(tmp_path, 'archive.tar.gz')
end

#checkObject

Check if repo is accessible



23
24
25
# File 'lib/capistrano/git/copy/utility.rb', line 23

def check
  git :'ls-remote --heads', repo_url
end

#cleanupObject

Cleanup repo cache



83
84
85
86
87
# File 'lib/capistrano/git/copy/utility.rb', line 83

def cleanup
  execute :rm, '-rf', tmp_path

  info 'Local repo cache was removed'
end

#cloneObject

Clone repo to cache



30
31
32
33
34
# File 'lib/capistrano/git/copy/utility.rb', line 30

def clone
  execute :mkdir, '-p', tmp_path

  git :clone, fetch(:repo_url), repo_path
end

#fetch_revisionObject

Set deployed revision



76
77
78
# File 'lib/capistrano/git/copy/utility.rb', line 76

def fetch_revision
  capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', fetch(:branch)).strip
end

#prepare_releaseObject

Create tar archive



56
57
58
# File 'lib/capistrano/git/copy/utility.rb', line 56

def prepare_release
  execute git_archive_all_bin, "--prefix=''", archive_path
end

#releaseObject

Upload and extract release



63
64
65
66
67
68
69
70
71
# File 'lib/capistrano/git/copy/utility.rb', line 63

def release
  remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path))

  upload! archive_path, remote_archive_path

  execute :mkdir, '-p', release_path
  execute :tar, '-f', remote_archive_path, '-x', '-C', release_path
  execute :rm, '-f', remote_archive_path
end

#repo_pathString

Path to repo cache



99
100
101
# File 'lib/capistrano/git/copy/utility.rb', line 99

def repo_path
  @_repo_path ||= File.join(tmp_path, 'repo')
end

#testBoolean

Check if repo cache exists



16
17
18
# File 'lib/capistrano/git/copy/utility.rb', line 16

def test
  test! " [ -d #{repo_path} ] "
end

#tmp_pathString

Temporary path for all git-copy operations



92
93
94
# File 'lib/capistrano/git/copy/utility.rb', line 92

def tmp_path
  @_tmp_path ||= File.join(Dir.tmpdir, deploy_id)
end

#updateObject

Update repo and submodules to branch



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/capistrano/git/copy/utility.rb', line 39

def update
  git :remote, :update
  git :reset, '--hard', commit_hash

  # submodules
  git :submodule, :init
  git :submodule, :update
  git :submodule, :foreach, '--recursive', :git, :submodule, :update, '--init'

  # cleanup
  git :clean, '-d', '-f'
  git :submodule, :foreach, '--recursive', :git, :clean, '-d', '-f'
end