Class: Git::Branches
Overview
object that holds all the available branches
Instance Method Summary collapse
-
#[](branch_name) ⇒ Git::Branch
Returns the target branch.
- #each(&block)
-
#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'
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/branches.rb', line 51 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)
34 35 36 |
# File 'lib/git/branches.rb', line 34 def each(&block) @branches.values.each(&block) end |
#local
20 21 22 |
# File 'lib/git/branches.rb', line 20 def local self.select { |b| !b.remote } end |
#remote
24 25 26 |
# File 'lib/git/branches.rb', line 24 def remote self.select { |b| b.remote } end |
#size
array like methods
30 31 32 |
# File 'lib/git/branches.rb', line 30 def size @branches.size end |
#to_s
63 64 65 66 67 68 69 |
# File 'lib/git/branches.rb', line 63 def to_s out = '' @branches.each do |k, b| out << (b.current ? '* ' : ' ') << b.to_s << "\n" end out end |