Class: Capistrano::SCM::Git

Inherits:
Plugin show all
Defined in:
lib/capistrano/scm/git.rb

Instance Method Summary collapse

Methods inherited from Plugin

#scm?

Methods included from DSL

#execute, #invoke, #invoke!, #local_user, #lock, #on, #revision_log_message, #rollback_log_message, #run_locally, #scm, #sudo, #t

Methods included from DSL::Stages

#stage_definitions, #stage_set?, #stages

Methods included from DSL::Paths

#asset_timestamp, #current_path, #deploy_config_path, #deploy_path, #deploy_to, #join_paths, #linked_dir_parents, #linked_dirs, #linked_file_dirs, #linked_files, #map_dirnames, #now, #release_path, #releases_path, #repo_path, #repo_url, #revision_log, #set_release_path, #shared_path, #stage_config_path

Methods included from DSL::Env

#asset_timestamp, #env, #release_roles, #release_timestamp, #role_properties, #roles

Methods included from TaskEnhancements

#after, #before, #default_tasks, #define_remote_file_task, #deploying?, #ensure_stage, #exit_deploy_because_of_exception, #tasks_without_stage_dependency

Instance Method Details

#archive_to_release_pathObject



67
68
69
70
71
72
73
74
75
# File 'lib/capistrano/scm/git.rb', line 67

def archive_to_release_path
  if (tree = fetch(:repo_tree))
    tree = tree.slice %r#^/?(.*?)/?$#, 1
    components = tree.split("/").size
    git :archive, fetch(:branch), tree, "| #{SSHKit.config.command_map[:tar]} -x --strip-components #{components} -f - -C", release_path
  else
    git :archive, fetch(:branch), "| #{SSHKit.config.command_map[:tar]} -x -f - -C", release_path
  end
end

#check_repo_is_reachableObject



39
40
41
# File 'lib/capistrano/scm/git.rb', line 39

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

#clone_repoObject



43
44
45
46
47
48
49
# File 'lib/capistrano/scm/git.rb', line 43

def clone_repo
  if (depth = fetch(:git_shallow_clone))
    git :clone, "--mirror", "--depth", depth, "--no-single-branch", git_repo_url, repo_path.to_s
  else
    git :clone, "--mirror", git_repo_url, repo_path.to_s
  end
end

#define_tasksObject



31
32
33
# File 'lib/capistrano/scm/git.rb', line 31

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

#fetch_revisionObject



77
78
79
# File 'lib/capistrano/scm/git.rb', line 77

def fetch_revision
  backend.capture(:git, "rev-list --max-count=1 #{fetch(:branch)}")
end

#git(*args) ⇒ Object



81
82
83
84
# File 'lib/capistrano/scm/git.rb', line 81

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

#git_repo_urlObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/capistrano/scm/git.rb', line 86

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

#register_hooksObject



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

def register_hooks
  after "deploy:new_release_path", "git:create_release"
  before "deploy:check", "git:check"
  before "deploy:set_current_revision", "git:set_current_revision"
end

#repo_mirror_exists?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/capistrano/scm/git.rb', line 35

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

#set_defaultsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/capistrano/scm/git.rb', line 8

def set_defaults
  set_if_empty :git_shallow_clone, false
  set_if_empty :git_wrapper_path, lambda {
    # Use a unique name that won't collide with other deployments, and
    # that cannot be guessed by other processes that have access to /tmp.
    "#{fetch(:tmp_dir)}/git-ssh-#{SecureRandom.hex(10)}.sh"
  }
  set_if_empty :git_environmental_variables, lambda {
    {
      git_askpass: "/bin/echo",
      git_ssh: fetch(:git_wrapper_path)
    }
  }
  set_if_empty :git_max_concurrent_connections, 10
  set_if_empty :git_wait_interval, 0
end

#update_mirrorObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/capistrano/scm/git.rb', line 51

def update_mirror
  # Update the origin URL if necessary.
  git :remote, "set-url", "origin", git_repo_url

  # Note: Requires git version 1.9 or greater
  if (depth = fetch(:git_shallow_clone))
    git :fetch, "--depth", depth, "origin", fetch(:branch)
  else
    git :remote, :update, "--prune"
  end
end

#verify_commitObject



63
64
65
# File 'lib/capistrano/scm/git.rb', line 63

def verify_commit
  git :"verify-commit", fetch_revision
end