Class: Librarian::Source::Git
- Inherits:
-
Object
- Object
- Librarian::Source::Git
- Defined in:
- lib/librarian/source/git.rb,
lib/librarian/source/git/repository.rb
Defined Under Namespace
Classes: Repository
Constant Summary collapse
- DEFAULTS =
{ :ref => 'master' }
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cache! ⇒ Object
-
#initialize(environment, uri, options) ⇒ Git
constructor
A new instance of Git.
- #pinned? ⇒ Boolean
- #to_lock_options ⇒ Object
- #to_s ⇒ Object
- #to_spec_args ⇒ Object
- #unpin! ⇒ Object
Methods included from Local
#found_path, #manifest_search_paths, #manifests
Methods included from Librarian::Support::AbstractMethod
Methods included from BasicApi
Constructor Details
#initialize(environment, uri, options) ⇒ Git
Returns a new instance of Git.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/librarian/source/git.rb', line 28 def initialize(environment, uri, ) self.environment = environment self.uri = uri self.ref = [:ref] || DEFAULTS[:ref] self.sha = [:sha] self.path = [:path] @repository = nil @repository_cache_path = nil ref.kind_of?(String) or raise TypeError, "ref must be a String" end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
22 23 24 |
# File 'lib/librarian/source/git.rb', line 22 def environment @environment end |
#path ⇒ Object
Returns the value of attribute path.
25 26 27 |
# File 'lib/librarian/source/git.rb', line 25 def path @path end |
#ref ⇒ Object
Returns the value of attribute ref.
25 26 27 |
# File 'lib/librarian/source/git.rb', line 25 def ref @ref end |
#sha ⇒ Object
Returns the value of attribute sha.
25 26 27 |
# File 'lib/librarian/source/git.rb', line 25 def sha @sha end |
#uri ⇒ Object
Returns the value of attribute uri.
25 26 27 |
# File 'lib/librarian/source/git.rb', line 25 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/librarian/source/git.rb', line 45 def ==(other) other && self.class == other.class && self.uri == other.uri && self.ref == other.ref && self.path == other.path && (self.sha.nil? || other.sha.nil? || self.sha == other.sha) end |
#cache! ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/librarian/source/git.rb', line 75 def cache! repository_cached? and return or repository_cached! unless repository.git? repository.path.rmtree if repository.path.exist? repository.path.mkpath repository.clone!(uri) end repository.reset_hard! repository.clean! unless repository.checked_out?(sha) remote = repository.default_remote repository.fetch!(remote) repository.fetch!(remote, :tags => true) self.sha = repository.hash_from(remote, ref) unless sha repository.checkout!(sha) unless repository.checked_out?(sha) raise Error, "failed to checkout #{sha}" unless repository.checked_out?(sha) end end |
#pinned? ⇒ Boolean
67 68 69 |
# File 'lib/librarian/source/git.rb', line 67 def pinned? !!sha end |
#to_lock_options ⇒ Object
61 62 63 64 65 |
# File 'lib/librarian/source/git.rb', line 61 def = {:remote => uri, :ref => ref, :sha => sha} .merge!(:path => path) if path end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/librarian/source/git.rb', line 41 def to_s path ? "#{uri}##{ref}(#{path})" : "#{uri}##{ref}" end |
#to_spec_args ⇒ Object
54 55 56 57 58 59 |
# File 'lib/librarian/source/git.rb', line 54 def to_spec_args = {} .merge!(:ref => ref) if ref != DEFAULTS[:ref] .merge!(:path => path) if path [uri, ] end |
#unpin! ⇒ Object
71 72 73 |
# File 'lib/librarian/source/git.rb', line 71 def unpin! @sha = nil end |