Class: Git::Worktrees Deprecated
- Inherits:
-
Object
- Object
- Git::Worktrees
- Includes:
- Enumerable
- Defined in:
- lib/git/worktrees.rb
Overview
Use Repository::WorktreeOperations#worktree_list instead
Repository::WorktreeOperations#worktree_list returns
Array<Git::WorktreeInfo> (immutable value objects). Look a worktree up
by path with worktree_list.find { |w| w.path == path } in place of
#[], and call Repository::WorktreeOperations#worktree_prune in
place of #prune. Constructing a Git::Worktrees emits a deprecation
warning.
Collection of all Git worktrees in a repository
Wraps every linked and main worktree and provides enumeration and path-based lookup.
Instance Method Summary collapse
-
#[](worktree_name) ⇒ Git::Worktree?
Returns the worktree with the given path.
-
#each
Iterates over every worktree in the collection.
-
#initialize(base)
constructor
deprecated
Deprecated.
Use Repository::WorktreeOperations#worktree_list instead
-
#prune ⇒ String
Removes stale administrative files for worktrees that no longer exist.
-
#size ⇒ Integer
Returns the number of worktrees in the collection.
-
#to_s ⇒ String
Returns a string listing all worktrees, one per line.
Constructor Details
#initialize(base)
Use Repository::WorktreeOperations#worktree_list instead
Creates a new Worktrees collection populated from the given repository
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/git/worktrees.rb', line 40 def initialize(base) Git::Deprecation.warn( 'Git::Worktrees is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#worktree_list instead.' ) @worktrees = {} @base = base # worktrees_all is deprecated too; silence it so one Git::Worktrees.new emits one warning Git::Deprecation.silence { worktree_repository.worktrees_all }.each do |w| @worktrees[w[0]] = Git::Worktree.new(@base, w[0], w[1]) end end |
Instance Method Details
#[](worktree_name) ⇒ Git::Worktree?
Returns the worktree with the given path
Supports lookup by the filesystem path of the worktree directory or by the full worktree descriptor (path and optional commitish).
105 106 107 108 109 |
# File 'lib/git/worktrees.rb', line 105 def [](worktree_name) @worktrees.values.each_with_object(@worktrees) do |worktree, worktrees| worktrees[worktree.full] ||= worktree end[worktree_name.to_s] end |
#each ⇒ Enumerator<Git::Worktree> #each {|worktree| ... } ⇒ Array<Git::Worktree>
Iterates over every worktree in the collection
88 89 90 |
# File 'lib/git/worktrees.rb', line 88 def each(&) @worktrees.values.each(&) end |
#prune ⇒ String
Removes stale administrative files for worktrees that no longer exist
Runs git worktree prune to clean up any lingering worktree metadata
for linked worktrees whose directories have been deleted.
138 139 140 |
# File 'lib/git/worktrees.rb', line 138 def prune worktree_repository.worktree_prune end |
#size ⇒ Integer
Returns the number of worktrees in the collection
62 63 64 |
# File 'lib/git/worktrees.rb', line 62 def size @worktrees.size end |
#to_s ⇒ String
Returns a string listing all worktrees, one per line
118 119 120 121 122 123 124 |
# File 'lib/git/worktrees.rb', line 118 def to_s out = +'' @worktrees.each_value do |b| out << b.to_s << "\n" end out end |