Class: Vx::SCM::Git
- Inherits:
-
Object
- Object
- Vx::SCM::Git
- Includes:
- Common::Helper::Shell
- Defined in:
- lib/vx/scm/git.rb,
lib/vx/scm/git/git_ssh.rb
Defined Under Namespace
Classes: GitSSH
Constant Summary collapse
- COMMIT_RE =
/^(.*) -:- (.*) \((.*)\) -:- (.*)$/
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#git_ssh ⇒ Object
readonly
Returns the value of attribute git_ssh.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pull_request_id ⇒ Object
readonly
Returns the value of attribute pull_request_id.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Class Method Summary collapse
Instance Method Summary collapse
- #commit_info ⇒ Object
- #fetch ⇒ Object
-
#initialize(src, sha, path, options = {}, &block) ⇒ Git
constructor
A new instance of Git.
- #make_fetch_command(options = {}) ⇒ Object
- #open ⇒ Object
Constructor Details
#initialize(src, sha, path, options = {}, &block) ⇒ Git
Returns a new instance of Git.
15 16 17 18 19 20 21 22 23 |
# File 'lib/vx/scm/git.rb', line 15 def initialize(src, sha, path, = {}, &block) @src = src @sha = sha @path = path @branch = [:branch] @git_ssh = GitSSH.new [:deploy_key] @pull_request_id = [:pull_request_id] @logger = block end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def branch @branch end |
#git_ssh ⇒ Object (readonly)
Returns the value of attribute git_ssh.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def git_ssh @git_ssh end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def path @path end |
#pull_request_id ⇒ Object (readonly)
Returns the value of attribute pull_request_id.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def pull_request_id @pull_request_id end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def sha @sha end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
13 14 15 |
# File 'lib/vx/scm/git.rb', line 13 def src @src end |
Class Method Details
.make_export_command(from, to) ⇒ Object
37 38 39 |
# File 'lib/vx/scm/git.rb', line 37 def self.make_export_command(from, to) %{ (cd '#{from}' && git checkout-index -a -f --prefix='#{to}/') }.strip end |
Instance Method Details
#commit_info ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vx/scm/git.rb', line 65 def commit_info rs = {} if str = commit_info_string if m = str.match(COMMIT_RE) rs.merge!( sha: m[1], author: m[2], email: m[3], message: m[4] ) end end OpenStruct.new rs end |
#fetch ⇒ Object
31 32 33 34 35 |
# File 'lib/vx/scm/git.rb', line 31 def fetch open do run_git make_fetch_command end end |
#make_fetch_command(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vx/scm/git.rb', line 41 def make_fetch_command( = {}) depth = .key?(:depth) ? [:depth] : 50 clone_branch = " --branch=#{branch}" if branch checkout_cmd = "git checkout -qf #{sha}" fetch_cmd = nil if pull_request_id clone_branch = "" fetch_cmd = "git fetch origin +refs/pull/#{pull_request_id}/merge:" checkout_cmd = "git checkout -q FETCH_HEAD" end clone_cmd = "git clone -q --depth=#{depth}#{clone_branch} #{src} #{path}" cmd = [] cmd << %{ echo "$ #{clone_cmd}" && #{clone_cmd} } cmd << %{ cd #{path} } cmd << %{ echo "$ #{fetch_cmd}" && #{fetch_cmd} } if fetch_cmd cmd << %{ echo "$ #{checkout_cmd}" && #{checkout_cmd} } cmd = cmd.join(" && ").gsub("\n", ' ').gsub(/\ +/, ' ').strip cmd end |
#open ⇒ Object
25 26 27 28 29 |
# File 'lib/vx/scm/git.rb', line 25 def open git_ssh.open do yield if block_given? end end |