Class: MultiRepo::Ref
- Inherits:
-
Object
- Object
- MultiRepo::Ref
- Defined in:
- lib/multirepo/git/ref.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #can_fast_forward_to?(ref) ⇒ Boolean
- #commit_id ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(repo, name) ⇒ Ref
constructor
A new instance of Ref.
- #merge_commit? ⇒ Boolean
- #short_commit_id ⇒ Object
Constructor Details
#initialize(repo, name) ⇒ Ref
Returns a new instance of Ref.
7 8 9 10 |
# File 'lib/multirepo/git/ref.rb', line 7 def initialize(repo, name) @repo = repo @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/multirepo/git/ref.rb', line 5 def name @name end |
Instance Method Details
#can_fast_forward_to?(ref) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/multirepo/git/ref.rb', line 31 def can_fast_forward_to?(ref) # http://stackoverflow.com/a/2934062/167983 rev_parse_output = GitRunner.run(@repo.path, "rev-parse #{@name}", Verbosity::OUTPUT_NEVER) merge_base_output = GitRunner.run(@repo.path, "merge-base \"#{rev_parse_output}\" \"#{ref.name}\"", Verbosity::OUTPUT_NEVER) return merge_base_output == rev_parse_output end |
#commit_id ⇒ Object
17 18 19 |
# File 'lib/multirepo/git/ref.rb', line 17 def commit_id GitRunner.run(@repo.path, "rev-parse #{@name}", Verbosity::OUTPUT_NEVER).strip end |
#exists? ⇒ Boolean
12 13 14 15 |
# File 'lib/multirepo/git/ref.rb', line 12 def exists? output = GitRunner.run(@repo.path, "rev-parse --verify --quiet #{@name}", Verbosity::OUTPUT_NEVER).strip return output != "" end |
#merge_commit? ⇒ Boolean
25 26 27 28 29 |
# File 'lib/multirepo/git/ref.rb', line 25 def merge_commit? lines = GitRunner.run(@repo.path, "cat-file -p #{@name}", Verbosity::OUTPUT_NEVER).split("\n") parents = lines.grep(/^parent /) return parents.count > 1 end |
#short_commit_id ⇒ Object
21 22 23 |
# File 'lib/multirepo/git/ref.rb', line 21 def short_commit_id GitRunner.run(@repo.path, "rev-parse --short #{@name}", Verbosity::OUTPUT_NEVER).strip end |