Class: R10K::Git::ShellGit::BaseRepository

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

Direct Known Subclasses

BareRepository, WorkingRepository

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Method Summary collapse

Methods included from Logging

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

Instance Method Details

#branchesArray<String>

Returns All local branches in this repository.

Returns:

  • (Array<String>)

    All local branches in this repository



28
29
30
# File 'lib/r10k/git/shellgit/base_repository.rb', line 28

def branches
  for_each_ref('refs/heads')
end

#git_dirPathname

This method is abstract.

Returns The path to the Git directory.

Returns:

  • (Pathname)

    The path to the Git directory

Raises:

  • (NotImplementedError)


8
9
10
# File 'lib/r10k/git/shellgit/base_repository.rb', line 8

def git_dir
  raise NotImplementedError
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



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

def ref_type(pattern)
  if branches.include? pattern
    :branch
  elsif tags.include? pattern
    :tag
  elsif resolve(pattern)
    :commit
  else
    :unknown
  end
end

#resolve(pattern) ⇒ String? Also known as: rev_parse

Resolve the given Git ref to a commit

Parameters:

  • pattern (String)

    The git ref to resolve

Returns:

  • (String, nil)

    The commit SHA if the ref could be resolved, nil otherwise.



16
17
18
19
20
21
# File 'lib/r10k/git/shellgit/base_repository.rb', line 16

def resolve(pattern)
  result = git ['rev-parse', "#{pattern}^{commit}"], :git_dir => git_dir.to_s, :raise_on_fail => false
  if result.success?
    result.stdout
  end
end

#tagsArray<String>

Returns All tags in this repository.

Returns:

  • (Array<String>)

    All tags in this repository



33
34
35
# File 'lib/r10k/git/shellgit/base_repository.rb', line 33

def tags
  for_each_ref('refs/tags')
end