Class: Branchtree::Branch::NullInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/branchtree/branch.rb

Direct Known Subclasses

InvalidInfo

Instance Method Summary collapse

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_parentObject



80
81
82
# File 'lib/branchtree/branch.rb', line 80

def ahead_of_parent
  0
end

#ahead_of_upstreamObject



92
93
94
# File 'lib/branchtree/branch.rb', line 92

def ahead_of_upstream
  0
end

#behind_parentObject



84
85
86
# File 'lib/branchtree/branch.rb', line 84

def behind_parent
  0
end

#behind_upstreamObject



96
97
98
# File 'lib/branchtree/branch.rb', line 96

def behind_upstream
  0
end

#empty?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/branchtree/branch.rb', line 72

def empty?
  true
end

#has_upstream?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/branchtree/branch.rb', line 88

def has_upstream?
  false
end

#populateObject



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

#repopulateObject



140
141
142
# File 'lib/branchtree/branch.rb', line 140

def repopulate
  populate
end

#valid?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/branchtree/branch.rb', line 76

def valid?
  true
end