Class: Git::Branches
Overview
object that holds all the available branches
Instance Method Summary collapse
-
#[](branch_name) ⇒ Git::Branch
Returns the target branch.
- #each
-
#initialize(base) ⇒ Branches
constructor
A new instance of Branches.
- #local
- #remote
-
#size
array like methods.
- #to_s
Constructor Details
Instance Method Details
#[](branch_name) ⇒ Git::Branch
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'
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/git/branches.rb', line 49 def [](branch_name) @branches.values.each_with_object(@branches) do |branch, branches| 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 =~ %r{^remotes/.+} end[branch_name.to_s] end |
#each
32 33 34 |
# File 'lib/git/branches.rb', line 32 def each(&) @branches.values.each(&) end |
#local
18 19 20 |
# File 'lib/git/branches.rb', line 18 def local reject(&:remote) end |
#remote
22 23 24 |
# File 'lib/git/branches.rb', line 22 def remote self.select(&:remote) end |
#size
array like methods
28 29 30 |
# File 'lib/git/branches.rb', line 28 def size @branches.size end |
#to_s
60 61 62 63 64 65 66 |
# File 'lib/git/branches.rb', line 60 def to_s out = '' @branches.each_value do |b| out << (b.current ? '* ' : ' ') << b.to_s << "\n" end out end |