class Git::Branches

object that holds all the available branches

Public Class Methods

new(base) click to toggle source
# File lib/git/branches.rb, line 8
def initialize(base)
  @branches = {}
  
  @base = base
        
  @base.lib.branches_all.each do |b|
    @branches[b[0]] = Git::Branch.new(@base, b[0])
  end
end

Public Instance Methods

[](branch_name) click to toggle source

Returns the target branch

Example:

Given (git branch -a):
 master
 remotes/working/master

g.branches['master'].full #=> 'master'
g.branches['working/master'].full => 'remotes/working/master'
g.branches['remotes/working/master'].full => 'remotes/working/master'

@param [#to_s] branch_name the target branch name. @return [Git::Branch] the target branch.

# File lib/git/branches.rb, line 49
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
each(&block) click to toggle source
# File lib/git/branches.rb, line 32
def each(&block)
  @branches.values.each(&block)
end
local() click to toggle source
# File lib/git/branches.rb, line 18
def local
  self.select { |b| !b.remote }
end
remote() click to toggle source
# File lib/git/branches.rb, line 22
def remote
  self.select { |b| b.remote }
end
size() click to toggle source

array like methods

# File lib/git/branches.rb, line 28
def size
  @branches.size
end
to_s() click to toggle source
# File lib/git/branches.rb, line 61
def to_s
  out = ''
  @branches.each do |k, b|
    out << (b.current ? '* ' : '  ') << b.to_s << "\n"
  end
  out
end