class Git::Branches
object that holds all the available branches
def [](branch_name)
-
(Git::Branch)
- the target branch.
Parameters:
-
branch_name
(#to_s
) -- the target branch name.
def [](branch_name) @branches.values.inject(@branches) do |branches, branch| branches[branch.full] ||= branch # This is how Git (version 1.7.9.5) works. # Lets you ignore the 'remotes' if its at the beginning of the branch full name (even if is not a real remote branch). branches[branch.full.sub('remotes/', '')] ||= branch if branch.full =~ /^remotes\/.+/ branches end[branch_name.to_s] end
def each(&block)
def each(&block) @branches.values.each(&block) end
def initialize(base)
def initialize(base) @branches = {} @base = base @base.lib.branches_all.each do |b| @branches[b[0]] = Git::Branch.new(@base, b[0]) end end
def local
def local self.select { |b| !b.remote } end
def remote
def remote self.select { |b| b.remote } end
def size
def size @branches.size end
def to_s
def to_s out = '' @branches.each do |k, b| out << (b.current ? '* ' : ' ') << b.to_s << "\n" end out end