Class: R10K::Git::Repository
- Inherits:
-
Object
- Object
- R10K::Git::Repository
- Defined in:
- lib/r10k/git/repository.rb
Overview
Define an abstract base class for git repositories.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
-
#dirname ⇒ Object
readonly
Returns the value of attribute dirname.
-
#git_dir ⇒ Object
readonly
Returns the value of attribute git_dir.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Instance Method Summary collapse
-
#remotes ⇒ Hash<String, String>
private
A hash of remote names and fetch URLs.
-
#resolve_commit(pattern) ⇒ Object
Define the same interface for resolving refs.
- #resolve_head(pattern) ⇒ Object
-
#resolve_ref(pattern) ⇒ String
(also: #rev_parse)
Resolve a ref to a git commit.
- #resolve_remote_head(pattern, remote = 'origin') ⇒ Object
- #resolve_tag(pattern) ⇒ Object
- #tags ⇒ Object
Instance Attribute Details
#basedir ⇒ Object (readonly)
Returns the value of attribute basedir.
13 14 15 |
# File 'lib/r10k/git/repository.rb', line 13 def basedir @basedir end |
#dirname ⇒ Object (readonly)
Returns the value of attribute dirname.
17 18 19 |
# File 'lib/r10k/git/repository.rb', line 17 def dirname @dirname end |
#git_dir ⇒ Object (readonly)
Returns the value of attribute git_dir.
24 25 26 |
# File 'lib/r10k/git/repository.rb', line 24 def git_dir @git_dir end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
9 10 11 |
# File 'lib/r10k/git/repository.rb', line 9 def remote @remote end |
Instance Method Details
#remotes ⇒ Hash<String, String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns A hash of remote names and fetch URLs.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/r10k/git/repository.rb', line 82 def remotes output = git ['remote', '-v'], :git_dir => git_dir ret = {} output.stdout.each_line do |line| next if line.match(/\(push\)/) name, url, _ = line.split(/\s+/) ret[name] = url end ret end |
#resolve_commit(pattern) ⇒ Object
Define the same interface for resolving refs.
72 73 74 75 76 77 78 |
# File 'lib/r10k/git/repository.rb', line 72 def resolve_commit(pattern) output = git ['rev-parse', "#{pattern}^{commit}"], :git_dir => git_dir, :raise_on_fail => false if output.success? output.stdout.chomp end end |
#resolve_head(pattern) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/r10k/git/repository.rb', line 54 def resolve_head(pattern) output = git ['show-ref', '--heads', '-s', pattern], :git_dir => git_dir, :raise_on_fail => false if output.success? output.stdout.lines.first end end |
#resolve_ref(pattern) ⇒ String Also known as: rev_parse
Resolve a ref to a git commit. The given pattern can be a commit, tag, or a local or remote branch
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/r10k/git/repository.rb', line 32 def resolve_ref(pattern) commit = resolve_tag(pattern) commit ||= resolve_remote_head(pattern) commit ||= resolve_head(pattern) commit ||= resolve_commit(pattern) if commit commit.chomp else raise R10K::Git::UnresolvableRefError.new(:ref => pattern, :git_dir => git_dir) end end |
#resolve_remote_head(pattern, remote = 'origin') ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/r10k/git/repository.rb', line 62 def resolve_remote_head(pattern, remote = 'origin') pattern = "refs/remotes/#{remote}/#{pattern}" output = git ['show-ref', '-s', pattern], :git_dir => git_dir, :raise_on_fail => false if output.success? output.stdout.lines.first end end |
#resolve_tag(pattern) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/r10k/git/repository.rb', line 46 def resolve_tag(pattern) output = git ['show-ref', '--tags', '-s', pattern], :git_dir => git_dir, :raise_on_fail => false if output.success? output.stdout.lines.first end end |
#tags ⇒ Object
95 96 97 98 99 100 |
# File 'lib/r10k/git/repository.rb', line 95 def entries = [] output = git(['tag', '-l'], :git_dir => @git_dir).stdout output.each_line { |line| entries << line.chomp } entries end |