Class: LearnTest::Git::Wip::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_test/git/wip/branch.rb

Direct Known Subclasses

Reference

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base:, name:) ⇒ Branch

Returns a new instance of Branch.



9
10
11
12
# File 'lib/learn_test/git/wip/branch.rb', line 9

def initialize(base:, name:)
  @base = base
  @name = name
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/learn_test/git/wip/branch.rb', line 7

def parent
  @parent
end

Instance Method Details

#last_revision(raise_no_commits: false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/learn_test/git/wip/branch.rb', line 14

def last_revision(raise_no_commits: false)
  @last_revision ||= begin
    begin
      @base.revparse(@name)
    rescue ::Git::GitExecuteError => e
      regex = Errors::NoCommitsError::REGEX

      if raise_no_commits
        raise e.message.match(regex) ? Errors::NoCommitsError.new(@name) : e
      end

      raise unless e.message.match(regex)

      false
    end
  end
end

#to_sObject



32
33
34
# File 'lib/learn_test/git/wip/branch.rb', line 32

def to_s
  @name
end