Class: Evrone::CI::SCM::Git

Inherits:
Object
  • Object
show all
Includes:
Common::Helper::Shell
Defined in:
lib/evrone/ci/scm/git.rb,
lib/evrone/ci/scm/git/git_ssh.rb

Defined Under Namespace

Classes: GitSSH

Constant Summary collapse

COMMIT_RE =
/^(.*) -:- (.*) \((.*)\) -:- (.*)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, sha, path, options = {}, &block) ⇒ Git

Returns a new instance of Git.



16
17
18
19
20
21
22
# 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

Instance Attribute Details

#git_sshObject (readonly)

Returns the value of attribute git_ssh.



14
15
16
# File 'lib/evrone/ci/scm/git.rb', line 14

def git_ssh
  @git_ssh
end

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/evrone/ci/scm/git.rb', line 14

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/evrone/ci/scm/git.rb', line 14

def path
  @path
end

#shaObject (readonly)

Returns the value of attribute sha.



14
15
16
# File 'lib/evrone/ci/scm/git.rb', line 14

def sha
  @sha
end

#srcObject (readonly)

Returns the value of attribute src.



14
15
16
# File 'lib/evrone/ci/scm/git.rb', line 14

def src
  @src
end

Class Method Details

.make_export_command(from, to) ⇒ Object



32
33
34
# 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

Instance Method Details

#commit_infoObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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

#fetchObject



24
25
26
27
28
29
30
# 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_commandObject



36
37
38
# 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