Class: Capistrano::NetStorage::SCM::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/capistrano/net_storage/scm/git.rb

Overview

Internal SCM class for Git repository

Instance Method Summary collapse

Methods inherited from Base

#sync_config

Instance Method Details

#checkObject



5
6
7
8
9
# File 'lib/capistrano/net_storage/scm/git.rb', line 5

def check
  run_locally do
    execute :git, 'ls-remote', repo_url, 'HEAD'
  end
end

#cloneObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/capistrano/net_storage/scm/git.rb', line 11

def clone
  c = config
  run_locally do
    if File.exist?("#{c.local_mirror_path}/HEAD")
      info t(:mirror_exists, at: c.local_mirror_path)
    else
      execute :git, :clone, '--mirror', repo_url, c.local_mirror_path
    end
  end
end

#prepare_archiveObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/capistrano/net_storage/scm/git.rb', line 41

def prepare_archive
  c = config
  run_locally do
    execute :mkdir, '-p', c.local_release_path

    within c.local_mirror_path do
      if tree = fetch(:repo_tree)
        stripped = tree.slice %r{^/?(.*?)/?$}, 1 # strip both side /
        num_components = stripped.count('/')
        execute(
          :git, :archive, fetch(:branch), tree,
          "| tar -x --strip-components #{num_components} -f - -C ",
          c.local_release_path
        )
      else
        execute :git, :archive, fetch(:branch), '| tar -x -C', c.local_release_path
      end
    end
  end
end

#set_current_revisionObject



31
32
33
34
35
36
37
38
39
# File 'lib/capistrano/net_storage/scm/git.rb', line 31

def set_current_revision
  return if fetch(:current_revision)
  c = config
  run_locally do
    within c.local_mirror_path do
      set :current_revision, capture(:git, "rev-list --max-count=1 #{fetch(:branch)}")
    end
  end
end

#updateObject



22
23
24
25
26
27
28
29
# File 'lib/capistrano/net_storage/scm/git.rb', line 22

def update
  c = config
  run_locally do
    within c.local_mirror_path do
      execute :git, :remote, :update
    end
  end
end