class Evrone::CI::SCM::Git

Constants

COMMIT_RE

Attributes

git_ssh[R]
logger[R]
path[R]
sha[R]
src[R]

Public Class Methods

make_export_command(from, to) click to toggle source
# File lib/evrone/ci/scm/git.rb, line 32
def self.make_export_command(from, to)
  %{ (cd '#{from}' && git checkout-index -a -f --prefix='#{to}/') }.strip
end
new(src, sha, path, options = {}, &block) click to toggle source
# File lib/evrone/ci/scm/git.rb, line 16
def initialize(src, sha, path, options = {}, &block)
  @src      = src
  @sha      = sha
  @path     = path
  @git_ssh  = GitSSH.new options[:deploy_key]
  @logger   = block
end

Public Instance Methods

commit_info() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 40
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() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 24
def fetch
  code = git_ssh.open do
    repo_exist? ? update : clone
  end
  code = checkout if code == 0
  code
end
make_fetch_command() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 36
def make_fetch_command
  %{ (test -d #{path} || git clone -q #{src} #{path}) && cd #{path} && git checkout -qf #{sha} }.strip
end

Private Instance Methods

checkout() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 85
def checkout
  run_git "git checkout -qf #{sha}", chdir: path
end
clone() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 81
def clone
  run_git "git clone -q #{src} #{path}"
end
commit_info_cmd() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 69
def commit_info_cmd
  %{git log -1 --pretty=format:'%H -:- %cn (%ce) -:- %s'}
end
commit_info_string() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 57
def commit_info_string
  output = ""
  code = spawn commit_info_cmd, chdir: path do |io|
    output << io
  end
  if code == 0
    output.strip
  else
    nil
  end
end
repo_exist?() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 73
def repo_exist?
  File.directory?(path.to_s + "/.git")
end
run_git(cmd, options = {}) click to toggle source
# File lib/evrone/ci/scm/git.rb, line 89
def run_git(cmd, options = {})
  env = {
    'GIT_SSH' => git_ssh.location.path
  }
  logger.call "$ #{cmd}\n"
  spawn(env, cmd, options, &logger)
end
update() click to toggle source
# File lib/evrone/ci/scm/git.rb, line 77
def update
  run_git 'git fetch origin', chdir: path
end