Class: R10K::Git::Rugged::BaseRepository
- Inherits:
-
Object
- Object
- R10K::Git::Rugged::BaseRepository
- Includes:
- Logging
- Defined in:
- lib/r10k/git/rugged/base_repository.rb
Direct Known Subclasses
Constant Summary
Constants included from Logging
Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP
Instance Attribute Summary collapse
-
#path ⇒ Pathname
readonly
The path to this repository.
Instance Method Summary collapse
- #branches ⇒ Object
-
#ref_type(pattern) ⇒ Symbol
The type of the given ref, one of :branch, :tag, :commit, or :unknown.
- #remotes ⇒ Object
- #resolve(pattern) ⇒ Object
- #tags ⇒ Object
-
#update_remote(remote, remote_name = 'origin') ⇒ Object
Update a remote URL.
Methods included from Logging
add_outputters, debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Instance Attribute Details
#path ⇒ Pathname (readonly)
Note:
The ‘@path` instance variable must be set by inheriting classes on instantiation.
Returns The path to this repository.
11 12 13 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 11 def path @path end |
Instance Method Details
#branches ⇒ Object
28 29 30 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 28 def branches with_repo { |repo| repo.branches.each_name(:local).to_a } end |
#ref_type(pattern) ⇒ Symbol
Returns The type of the given ref, one of :branch, :tag, :commit, or :unknown.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 37 def ref_type(pattern) # Try to match and resolve SHA refs as quickly as possible. if pattern =~ /^[0-9a-f]{5,40}$/i && @_rugged_repo.include?(pattern) :commit elsif @_rugged_repo.[pattern] :tag elsif @_rugged_repo.branches[pattern] :branch elsif resolve(pattern) :commit else :unknown end end |
#remotes ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 52 def remotes remotes_hash = {} if @_rugged_repo @_rugged_repo.remotes.each do |remote| remotes_hash[remote.name] = remote.url end end remotes_hash end |
#resolve(pattern) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 13 def resolve(pattern) object = with_repo { |repo| repo.rev_parse(pattern) } case object when NilClass nil when ::Rugged::Tag, ::Rugged::Tag::Annotation object.target.oid else object.oid end rescue ::Rugged::ReferenceError, ::Rugged::OdbError => e logger.debug2(_("Unable to resolve %{pattern}: %{e} ") % {pattern: pattern, e: e }) nil end |
#tags ⇒ Object
32 33 34 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 32 def with_repo { |repo| repo..each_name.to_a } end |
#update_remote(remote, remote_name = 'origin') ⇒ Object
Update a remote URL
67 68 69 70 71 72 |
# File 'lib/r10k/git/rugged/base_repository.rb', line 67 def update_remote(remote, remote_name='origin') if @_rugged_repo logger.debug2(_("Remote URL is different from cache, updating %{orig} to %{update}") % {orig: remotes[remote_name], update: remote}) @_rugged_repo.remotes.set_url(remote_name, remote) end end |