Module: Batali::Git

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Load attributes into class



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

def self.included(klass)
  klass.class_eval do
    attribute :url, String, :required => true, :equivalent => true
    attribute :ref, String, :required => true, :equivalent => true
    attribute :cache, String, :default => File.join(Dir.home, '.batali/cache/git')
  end
end

Instance Method Details

#base_pathString

Returns path to repository clone.

Returns:

  • (String)

    path to repository clone



8
9
10
# File 'lib/batali/git.rb', line 8

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

#clone_repositoryTrueClass

Clone the repository to the local machine

Returns:

  • (TrueClass)


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

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



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

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, 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
  self.path
end