Class: Capistrano::SCM::GitWithSubmoduleAndResolvSymlinks

Inherits:
Plugin
  • Object
show all
Defined in:
lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb,
lib/capistrano/scm/git_with_submodule_and_resolv_symlinks/version.rb

Constant Summary collapse

VERSION =
"0.3.3"

Instance Method Summary collapse

Instance Method Details

#check_repo_is_reachableObject



44
45
46
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 44

def check_repo_is_reachable
  git :'ls-remote', git_repo_url, "HEAD"
end

#clone_repoObject



48
49
50
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 48

def clone_repo
  git :clone, git_repo_url, repo_path.to_s
end

#define_tasksObject



36
37
38
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 36

def define_tasks
  eval_rakefile File.expand_path("../tasks/git_with_submodule_and_resolv_symlinks.rake", __FILE__)
end

#fetch_revisionObject



67
68
69
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 67

def fetch_revision
  backend.capture(:git, "rev-list", "--max-count=1", real_branch)
end

#git(*args) ⇒ Object



79
80
81
82
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 79

def git(*args)
  args.unshift :git
  backend.execute(*args)
end

#git_repo_urlObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 84

def git_repo_url
  if fetch(:git_http_username) && fetch(:git_http_password)
    URI.parse(repo_url).tap do |repo_uri|
      repo_uri.user     = fetch(:git_http_username)
      repo_uri.password = CGI.escape(fetch(:git_http_password))
    end.to_s
  elsif fetch(:git_http_username)
    URI.parse(repo_url).tap do |repo_uri|
      repo_uri.user = fetch(:git_http_username)
    end.to_s
  else
    repo_url
  end
end

#nspObject



10
11
12
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 10

def nsp
  "git_with_submodule_and_resolv_symlinks"
end

#real_branchObject



71
72
73
74
75
76
77
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 71

def real_branch
  @real_branch ||= if backend.test(:git, :"rev-parse", "origin/#{fetch(:branch)}")
                     "origin/#{fetch(:branch)}"
                   else
                     fetch(:branch)
                   end
end

#register_hooksObject



29
30
31
32
33
34
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 29

def register_hooks
  nsp = "git_with_submodule_and_resolv_symlinks"
  after "deploy:new_release_path", "#{nsp}:create_release"
  before "deploy:check", "#{nsp}:check"
  before "deploy:set_current_revision", "#{nsp}:set_current_revision"
end

#releaseObject



59
60
61
62
63
64
65
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 59

def release
  if fetch(:repo_tree)
    backend.execute "rsync -ar --copy-links --exclude=.git\* #{repo_path}/#{fetch(:repo_tree)}/ #{release_path}"
  else
    backend.execute "rsync -ar --copy-links --exclude=.git\* #{repo_path}/ #{release_path}"
  end
end

#repo_mirror_exists?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 40

def repo_mirror_exists?
  backend.test " [ -d #{repo_path}/.git ] "
end

#set_defaultsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 14

def set_defaults
  set_if_empty :"#{nsp}_wrapper_path", lambda {
    # Try to avoid permissions issues when multiple users deploy the same app
    # by using different file names in the same dir for each deployer and stage.
    suffix = [:application, :stage, :local_user].map { |key| fetch(key).to_s }.join("-")
    "#{fetch(:tmp_dir)}/git-ssh-#{suffix}.sh"
  }
  set_if_empty :"#{nsp}_environmental_variables", lambda {
    {
      git_askpass: "/bin/echo",
      git_ssh: fetch(:"#{nsp}_wrapper_path")
    }
  }
end

#update_mirrorObject



52
53
54
55
56
57
# File 'lib/capistrano/scm/git_with_submodule_and_resolv_symlinks.rb', line 52

def update_mirror
  git :remote, "set-url", "origin", git_repo_url
  git :remote, :update, "--prune"
  git :checkout, "--detach", real_branch
  git :submodule, :update, "--init"
end