Module: Batali::Git
- Included in:
- Origin::Git, Source::Git
- Defined in:
- lib/batali/git.rb
Class Method Summary collapse
-
.included(klass) ⇒ Object
Load attributes into class.
Instance Method Summary collapse
-
#base_path ⇒ String
Path to repository clone.
-
#clone_repository ⇒ TrueClass
Clone the repository to the local machine.
-
#ref_dup ⇒ String
Duplicate reference and store.
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_path ⇒ String
Returns 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_repository ⇒ TrueClass
Clone the repository to the local machine
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_dup ⇒ String
Note:
this will update ref to SHA
Duplicate reference and store
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 |