class GitProc::GitBranches

Public Class Methods

new(lib, opt = {}) click to toggle source
# File lib/git-process/git_branches.rb, line 22
def initialize(lib, opt = {})
  @lib = lib
  branch_opts = {:no_color => true}
  if opt[:remote]
    branch_opts[:remote] = true
  elsif opt[:local]
    branch_opts[:local] = true
  else
    branch_opts[:all] = true
  end
  branch_lines = lib.branch(nil, branch_opts).split("\n")
  @items = SortedSet.new
  branch_lines.each do |bl|
    @items << GitBranch.new(bl[2..-1], bl[0..0] == '*', lib)
  end
end

Public Instance Methods

<<(item) click to toggle source
# File lib/git-process/git_branches.rb, line 40
def <<(item)
  @items << item
end
[](branch_name) click to toggle source
# File lib/git-process/git_branches.rb, line 70
def [](branch_name)
  branch_name = current.name if branch_name == 'HEAD'
  br = @items.find { |b| b.name == branch_name }
  if br.nil? and branch_name !~ /origin\// and branch_name != '_parking_'
    @lib.logger.warn { "Could not find '#{branch_name}' in #{@items.map { |i| i.name }.join(',')}" }
  end
  br
end
current() click to toggle source
# File lib/git-process/git_branches.rb, line 55
def current
  @items.find { |b| b.current? }
end
each(&block) click to toggle source
# File lib/git-process/git_branches.rb, line 45
def each(&block)
  @items.each { |b| block.call(b) }
end
include?(branch_name) click to toggle source
# File lib/git-process/git_branches.rb, line 65
def include?(branch_name)
  @items.any? { |b| b.name == branch_name }
end
names() click to toggle source
# File lib/git-process/git_branches.rb, line 50
def names
  @items.map { |b| b.name }
end
parking() click to toggle source
# File lib/git-process/git_branches.rb, line 60
def parking
  @items.find { |b| b.name == '_parking_' }
end