Class: Git::Branches Deprecated
Overview
Use Repository::Branching#branch_list instead
Repository::Branching#branch_list returns Array<Git::BranchInfo>
(immutable value objects). Filter it with select(&:remote?) or
reject(&:remote?) in place of #remote and #local, and look a
branch up by name with branch_list(name).first in place of #[].
Constructing a Git::Branches emits a deprecation warning.
Collection of all Git branches in a repository
Wraps both local and remote-tracking branches and provides filtering, enumeration, and name-based lookup.
Instance Method Summary collapse
-
#[](branch_name) ⇒ Git::Branch?
Returns the branch with the given name.
-
#each
Iterates over every branch in the collection.
-
#initialize(base)
constructor
deprecated
Deprecated.
Use Repository::Branching#branch_list instead
-
#local ⇒ Array<Git::Branch>
Returns all local (non-remote-tracking) branches.
-
#remote ⇒ Array<Git::Branch>
Returns all remote-tracking branches.
-
#size ⇒ Integer
Returns the number of branches in the collection.
-
#to_s ⇒ String
Returns a string listing all branches, prefixed with
*for the current branch.
Constructor Details
#initialize(base)
Use Repository::Branching#branch_list instead
Creates a new Branches collection populated from the given repository
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/git/branches.rb', line 39 def initialize(base) Git::Deprecation.warn( 'Git::Branches is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#branch_list instead.' ) @branches = {} @lookup = {} @base = base load_branches end |
Instance Method Details
#[](branch_name) ⇒ Git::Branch?
Returns the branch with the given name
Supports short names ('main'), remote-qualified names
('working/master'), and full refspec names
('remotes/working/master').
127 128 129 |
# File 'lib/git/branches.rb', line 127 def [](branch_name) @lookup[branch_name.to_s] end |
#each ⇒ Enumerator<Git::Branch> #each {|branch| ... } ⇒ Array<Git::Branch>
Iterates over every branch in the collection
107 108 109 |
# File 'lib/git/branches.rb', line 107 def each(&) @branches.values.each(&) end |
#local ⇒ Array<Git::Branch>
Returns all local (non-remote-tracking) branches
59 60 61 |
# File 'lib/git/branches.rb', line 59 def local reject(&:remote) end |
#remote ⇒ Array<Git::Branch>
Returns all remote-tracking branches
70 71 72 |
# File 'lib/git/branches.rb', line 70 def remote self.select(&:remote) end |
#size ⇒ Integer
Returns the number of branches in the collection
81 82 83 |
# File 'lib/git/branches.rb', line 81 def size @branches.size end |
#to_s ⇒ String
Returns a string listing all branches, prefixed with * for the current branch
138 139 140 141 142 143 144 145 146 |
# File 'lib/git/branches.rb', line 138 def to_s out = +'' @branches.each_value do |b| # Git::Branch#current is deprecated too; silence it so one to_s call emits one warning current = Git::Deprecation.silence { b.current } out << (current ? '* ' : ' ') << b.to_s << "\n" end out end |