Class: R10K::Git::ShellGit::BaseRepository
- Inherits:
-
Object
- Object
- R10K::Git::ShellGit::BaseRepository
- Includes:
- Logging
- Defined in:
- lib/r10k/git/shellgit/base_repository.rb
Direct Known Subclasses
Constant Summary
Constants included from Logging
Instance Method Summary collapse
-
#branches ⇒ Array<String>
All local branches in this repository.
-
#git_dir ⇒ Pathname
abstract
The path to the Git directory.
-
#ref_type(pattern) ⇒ Symbol
The type of the given ref, one of :branch, :tag, :commit, or :unknown.
-
#remotes ⇒ Hash
Collection of remotes for this repo, keys are the remote name and values are the remote URL.
-
#resolve(pattern) ⇒ String?
(also: #rev_parse)
Resolve the given Git ref to a commit.
-
#tags ⇒ Array<String>
All tags in this repository.
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Instance Method Details
#branches ⇒ Array<String>
29 30 31 |
# File 'lib/r10k/git/shellgit/base_repository.rb', line 29 def branches for_each_ref('refs/heads') end |
#git_dir ⇒ Pathname
This method is abstract.
Returns The path to the Git directory.
9 10 11 |
# File 'lib/r10k/git/shellgit/base_repository.rb', line 9 def git_dir raise NotImplementedError end |
#ref_type(pattern) ⇒ Symbol
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/r10k/git/shellgit/base_repository.rb', line 39 def ref_type(pattern) if branches.include? pattern :branch elsif .include? pattern :tag elsif resolve(pattern) :commit else :unknown end end |
#remotes ⇒ Hash
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/r10k/git/shellgit/base_repository.rb', line 52 def remotes result = git ['config', '--local', '--get-regexp', '^remote\..*\.url$'], :git_dir => git_dir.to_s, :raise_on_fail => false if result.success? Hash[ result.stdout.split("\n").collect do |remote| matches = /^remote\.(.*)\.url (.*)$/.match(remote) [matches[1], matches[2]] end ] else {} end end |
#resolve(pattern) ⇒ String? Also known as: rev_parse
Resolve the given Git ref to a commit
17 18 19 20 21 22 |
# File 'lib/r10k/git/shellgit/base_repository.rb', line 17 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 |
#tags ⇒ Array<String>
34 35 36 |
# File 'lib/r10k/git/shellgit/base_repository.rb', line 34 def for_each_ref('refs/tags') end |