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
-
#git_ops_count ⇒ Object
For tests.
-
#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.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/librarian/source/git.rb', line 29 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.
23 24 25 |
# File 'lib/librarian/source/git.rb', line 23 def environment @environment end |
#path ⇒ Object
Returns the value of attribute path.
26 27 28 |
# File 'lib/librarian/source/git.rb', line 26 def path @path end |
#ref ⇒ Object
Returns the value of attribute ref.
26 27 28 |
# File 'lib/librarian/source/git.rb', line 26 def ref @ref end |
#sha ⇒ Object
Returns the value of attribute sha.
26 27 28 |
# File 'lib/librarian/source/git.rb', line 26 def sha @sha end |
#uri ⇒ Object
Returns the value of attribute uri.
26 27 28 |
# File 'lib/librarian/source/git.rb', line 26 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/librarian/source/git.rb', line 46 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/librarian/source/git.rb', line 76 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) raise Error, "failed to clone #{uri}" unless repository.git? end # Probably unnecessary: nobody should be writing to our cache but us. # Just a precaution. repository_clean_once! unless sha repository_update_once! self.sha = fetch_sha_memo end unless repository.checked_out?(sha) repository_update_once! unless repository.has_commit?(sha) repository.checkout!(sha) # Probably unnecessary: if git fails to checkout, it should exit # nonzero, and we should expect Librarian::Posix::CommandFailure. raise Error, "failed to checkout #{sha}" unless repository.checked_out?(sha) end end |
#git_ops_count ⇒ Object
For tests
105 106 107 |
# File 'lib/librarian/source/git.rb', line 105 def git_ops_count repository.git_ops_history.size end |
#pinned? ⇒ Boolean
68 69 70 |
# File 'lib/librarian/source/git.rb', line 68 def pinned? !!sha end |
#to_lock_options ⇒ Object
62 63 64 65 66 |
# File 'lib/librarian/source/git.rb', line 62 def = {:remote => uri, :ref => ref, :sha => sha} .merge!(:path => path) if path end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/librarian/source/git.rb', line 42 def to_s path ? "#{uri}##{ref}(#{path})" : "#{uri}##{ref}" end |
#to_spec_args ⇒ Object
55 56 57 58 59 60 |
# File 'lib/librarian/source/git.rb', line 55 def to_spec_args = {} .merge!(:ref => ref) if ref != DEFAULTS[:ref] .merge!(:path => path) if path [uri, ] end |
#unpin! ⇒ Object
72 73 74 |
# File 'lib/librarian/source/git.rb', line 72 def unpin! @sha = nil end |