Class: Capistrano::SCM::Git
- Defined in:
- lib/capistrano/scm/git.rb
Instance Method Summary collapse
- #archive_to_release_path ⇒ Object
- #check_repo_is_reachable ⇒ Object
- #clone_repo ⇒ Object
- #define_tasks ⇒ Object
- #fetch_revision ⇒ Object
- #fetch_revision_time ⇒ Object
- #git(*args) ⇒ Object
- #git_repo_url ⇒ Object
- #register_hooks ⇒ Object
- #repo_mirror_exists? ⇒ Boolean
- #set_defaults ⇒ Object
- #update_mirror ⇒ Object
- #verify_commit ⇒ Object
Methods inherited from Plugin
Instance Method Details
#archive_to_release_path ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/capistrano/scm/git.rb', line 69 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_reachable ⇒ Object
41 42 43 |
# File 'lib/capistrano/scm/git.rb', line 41 def check_repo_is_reachable git :'ls-remote', git_repo_url, "HEAD" end |
#clone_repo ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/capistrano/scm/git.rb', line 45 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_tasks ⇒ Object
33 34 35 |
# File 'lib/capistrano/scm/git.rb', line 33 def define_tasks eval_rakefile File.("../tasks/git.rake", __FILE__) end |
#fetch_revision ⇒ Object
79 80 81 |
# File 'lib/capistrano/scm/git.rb', line 79 def fetch_revision backend.capture(:git, "rev-list --max-count=1 #{fetch(:branch)}") end |
#fetch_revision_time ⇒ Object
83 84 85 |
# File 'lib/capistrano/scm/git.rb', line 83 def fetch_revision_time backend.capture(:git, "--no-pager log -1 --pretty=format:\"%ct\" #{fetch(:branch)}") end |
#git(*args) ⇒ Object
87 88 89 90 |
# File 'lib/capistrano/scm/git.rb', line 87 def git(*args) args.unshift :git backend.execute(*args) end |
#git_repo_url ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/capistrano/scm/git.rb', line 92 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_hooks ⇒ Object
26 27 28 29 30 31 |
# File 'lib/capistrano/scm/git.rb', line 26 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" before "deploy:set_current_revision_time", "git:set_current_revision_time" end |
#repo_mirror_exists? ⇒ Boolean
37 38 39 |
# File 'lib/capistrano/scm/git.rb', line 37 def repo_mirror_exists? backend.test " [ -f #{repo_path}/HEAD ] " end |
#set_defaults ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/capistrano/scm/git.rb', line 9 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_mirror ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/capistrano/scm/git.rb', line 53 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_commit ⇒ Object
65 66 67 |
# File 'lib/capistrano/scm/git.rb', line 65 def verify_commit git :"verify-commit", fetch_revision end |