Class: R10K::Git::Rugged::BaseRepository

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/r10k/git/rugged/base_repository.rb

Direct Known Subclasses

BareRepository, WorkingRepository

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Instance Attribute Details

#pathPathname (readonly)

Note:

The ‘@path` instance variable must be set by inheriting classes on instantiation.

Returns The path to this repository.

Returns:

  • (Pathname)

    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

#branchesObject



27
28
29
# File 'lib/r10k/git/rugged/base_repository.rb', line 27

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.

Returns:

  • (Symbol)

    The type of the given ref, one of :branch, :tag, :commit, or :unknown



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/r10k/git/rugged/base_repository.rb', line 36

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.tags[pattern]
    :tag
  elsif @_rugged_repo.branches[pattern]
    :branch
  elsif resolve(pattern)
    :commit
  else
    :unknown
  end
end

#remotesObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/r10k/git/rugged/base_repository.rb', line 51

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
# 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
  nil
end

#tagsObject



31
32
33
# File 'lib/r10k/git/rugged/base_repository.rb', line 31

def tags
  with_repo { |repo| repo.tags.each_name.to_a }
end