Class: Vx::Common::Git
- Inherits:
-
Object
- Object
- Vx::Common::Git
- Defined in:
- lib/vx/common/git.rb
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.
Instance Method Summary collapse
- #fetch_cmd(options = {}) ⇒ Object
- #git_ssh_content(key_location) ⇒ Object
-
#initialize(src, sha, path, options = {}, &block) ⇒ Git
constructor
A new instance of Git.
Constructor Details
#initialize(src, sha, path, options = {}, &block) ⇒ Git
Returns a new instance of Git.
12 13 14 15 16 17 18 19 |
# File 'lib/vx/common/git.rb', line 12 def initialize(src, sha, path, = {}, &block) @src = src @sha = sha @path = path @branch = [:branch] @pull_request_id = [:pull_request_id] @logger = block end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def branch @branch end |
#git_ssh ⇒ Object (readonly)
Returns the value of attribute git_ssh.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def git_ssh @git_ssh end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def path @path end |
#pull_request_id ⇒ Object (readonly)
Returns the value of attribute pull_request_id.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def pull_request_id @pull_request_id end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def sha @sha end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
10 11 12 |
# File 'lib/vx/common/git.rb', line 10 def src @src end |
Instance Method Details
#fetch_cmd(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vx/common/git.rb', line 31 def fetch_cmd( = {}) 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}/head" checkout_cmd = "git checkout -q FETCH_HEAD" end clone_cmd = "git clone --depth=#{depth}#{clone_branch} #{src} #{path}" cmd = [] cmd << %{ echo "$ #{clone_cmd}" } cmd << clone_cmd if fetch_cmd cmd << %{ echo "$ #{fetch_cmd}" } cmd << %{ ( cd #{path} && #{fetch_cmd} ) } end cmd << %{ echo "$ #{checkout_cmd}" } cmd << %{ ( cd #{path} && #{checkout_cmd} ) } cmd.join("\n") end |
#git_ssh_content(key_location) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/vx/common/git.rb', line 21 def git_ssh_content(key_location) key = key_location ? "-i #{key_location}" : "" out = "#!/bin/sh\n" out << "exec /usr/bin/ssh" out << " -A -o LogLevel=quiet" out << " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" out << " #{key} $@\n" out end |