Class: Branchtree::Branch::NullInfo
- Inherits:
-
Object
- Object
- Branchtree::Branch::NullInfo
- Defined in:
- lib/branchtree/branch.rb
Direct Known Subclasses
Instance Method Summary collapse
- #ahead_of_parent ⇒ Object
- #ahead_of_upstream ⇒ Object
- #behind_parent ⇒ Object
- #behind_upstream ⇒ Object
- #empty? ⇒ Boolean
- #has_upstream? ⇒ Boolean
-
#initialize(branch) ⇒ NullInfo
constructor
A new instance of NullInfo.
- #populate ⇒ Object
- #repopulate ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(branch) ⇒ NullInfo
Returns a new instance of NullInfo.
68 69 70 |
# File 'lib/branchtree/branch.rb', line 68 def initialize(branch) @branch = branch end |
Instance Method Details
#ahead_of_parent ⇒ Object
80 81 82 |
# File 'lib/branchtree/branch.rb', line 80 def ahead_of_parent 0 end |
#ahead_of_upstream ⇒ Object
92 93 94 |
# File 'lib/branchtree/branch.rb', line 92 def ahead_of_upstream 0 end |
#behind_parent ⇒ Object
84 85 86 |
# File 'lib/branchtree/branch.rb', line 84 def behind_parent 0 end |
#behind_upstream ⇒ Object
96 97 98 |
# File 'lib/branchtree/branch.rb', line 96 def behind_upstream 0 end |
#empty? ⇒ Boolean
72 73 74 |
# File 'lib/branchtree/branch.rb', line 72 def empty? true end |
#has_upstream? ⇒ Boolean
88 89 90 |
# File 'lib/branchtree/branch.rb', line 88 def has_upstream? false end |
#populate ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/branchtree/branch.rb', line 100 def populate # Are we valid? valid_result = @branch.cmd.run!("git", "rev-parse", "--verify", "--quiet", @branch.full_ref) unless valid_result.success? return @branch.info = InvalidInfo.new(@branch) end parent_behind, parent_ahead = 0, 0 if @branch.parent && @branch.parent.info.valid? # Count ahead-behind from parent ahead_behind_parent = @branch.cmd.run( "git", "rev-list", "--left-right", "--count", "refs/heads/#{@branch.parent_branch_name}...#{@branch.full_ref}", ).out.chomp parent_behind, parent_ahead = ahead_behind_parent.split(/\t/, 2).map(&:to_i) end # Idenfity if we have an upstream upstream_ref, upstream_behind, upstream_ahead = "", 0, 0 upstream_result = @branch.cmd.run!( "git", "rev-parse", "--symbolic-full-name", "#{@branch.name}@{u}", ) if upstream_result.success? upstream_ref = upstream_result.out.chomp ahead_behind_upstream = @branch.cmd.run( "git", "rev-list", "--left-right", "--count", "#{upstream_ref}...#{@branch.full_ref}", ).out.chomp upstream_behind, upstream_ahead = ahead_behind_upstream.split(/\t/, 2).map(&:to_i) end @branch.info = Info.new( branch: @branch, ahead_of_parent: parent_ahead, behind_parent: parent_behind, upstream: upstream_ref, ahead_of_upstream: upstream_ahead, behind_upstream: upstream_behind, ) end |
#repopulate ⇒ Object
140 141 142 |
# File 'lib/branchtree/branch.rb', line 140 def repopulate populate end |
#valid? ⇒ Boolean
76 77 78 |
# File 'lib/branchtree/branch.rb', line 76 def valid? true end |