Module: Batali::Git

Included in:
Origin::Git, Source::Git
Defined in:
lib/batali/git.rb

Overview

Helper module for git interactions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Load attributes into class



48
49
50
51
52
53
# File 'lib/batali/git.rb', line 48

def self.included(klass)
  klass.class_eval do
    attribute :url, String, :required => true, :equivalent => true
    attribute :ref, String, :required => true, :equivalent => true
  end
end

Instance Method Details

#base_pathString

Returns path to repository clone.

Returns:

  • (String)

    path to repository clone



10
11
12
# File 'lib/batali/git.rb', line 10

def base_path
  File.join(cache_path, Base64.urlsafe_encode64(url))
end

#clone_repositoryTrueClass

Clone the repository to the local machine

Returns:

  • (TrueClass)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/batali/git.rb', line 17

def clone_repository
  if(File.directory?(base_path))
    repo = ::Git.open(base_path)
    repo.checkout('master')
    repo.pull
    repo.fetch
  else
    ::Git.clone(url, base_path)
  end
  true
end

#ref_dupString

Note:

this will update ref to SHA

Duplicate reference and store

Returns:

  • (String)

    commit SHA



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/batali/git.rb', line 33

def ref_dup
  git = ::Git.open(base_path)
  git.checkout(ref)
  git.pull('origin', ref)
  self.ref = git.log.first.sha
  self.path = File.join(cache_path, 'git', ref)
  unless(File.directory?(path))
    FileUtils.mkdir_p(path)
    FileUtils.cp_r(File.join(base_path, '.'), path)
    FileUtils.rm_rf(File.join(path, '.git'))
  end
  path
end