Module: Git::Repository::WorktreeOperations Private
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/worktree_operations.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Facade methods for worktree operations: listing, adding, removing, moving, locking, repairing, and pruning worktrees
Included by Git::Repository.
Instance Method Summary collapse
-
#worktree(dir, commitish = nil) ⇒ Git::Worktree
deprecated
private
Deprecated.
Use #worktree_add and #worktree_remove instead
repo.worktree(dir, commitish).addbecomesrepo.worktree_add(dir, commitish)andrepo.worktree(dir).removebecomesrepo.worktree_remove(dir). Read a worktree's checked-out commit from WorktreeInfo#head via #worktree_list. -
#worktree_add(dir, commitish = nil) ⇒ String
private
Create a new linked worktree at the given directory.
-
#worktree_list ⇒ Array<Git::WorktreeInfo>
private
Returns every worktree attached to the repository.
-
#worktree_lock(worktree, opts = {}) ⇒ String
private
Lock a linked worktree so that
git worktree pruneleaves it alone. -
#worktree_move(worktree, new_path, opts = {}) ⇒ String
private
Move a linked worktree to a new location.
-
#worktree_prune ⇒ String
private
Prune stale worktree administrative files.
-
#worktree_remove(worktree) ⇒ String
private
Remove a linked worktree.
-
#worktree_repair(*paths) ⇒ String
private
Repair the links between the repository and its linked worktrees.
-
#worktree_unlock(worktree) ⇒ String
private
Unlock a linked worktree.
-
#worktrees ⇒ Git::Worktrees
deprecated
private
Deprecated.
Use #worktree_list instead
#worktree_list returns
Array<Git::WorktreeInfo>. Look a worktree up by path withworktree_list.find { |w| w.path == path }in place ofworktrees[path], and call #worktree_prune in place ofworktrees.prune. Calling this method emits one deprecation warning. -
#worktrees_all ⇒ Array<Array(String, String)>
deprecated
private
Deprecated.
Use #worktree_list instead
#worktree_list returns one WorktreeInfo per worktree, with
pathandheadin place of the pair, and includes the main worktree of a bare repository.
Instance Method Details
#worktree(dir, commitish = nil) ⇒ Git::Worktree
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #worktree_add and #worktree_remove instead
repo.worktree(dir, commitish).add becomes
repo.worktree_add(dir, commitish) and repo.worktree(dir).remove
becomes repo.worktree_remove(dir). Read a worktree's checked-out
commit from WorktreeInfo#head via #worktree_list.
Return a Worktree object for the given directory and optional commitish
This is a factory method — it constructs the domain object but does not immediately execute any git commands.
294 295 296 297 298 299 300 |
# File 'lib/git/repository/worktree_operations.rb', line 294 def worktree(dir, commitish = nil) Git::Deprecation.warn( 'Git::Repository#worktree is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#worktree_add and Git::Repository#worktree_remove instead.' ) Git::Worktree.new(self, dir, commitish) end |
#worktree_add(dir, commitish = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new linked worktree at the given directory
104 105 106 107 108 109 |
# File 'lib/git/repository/worktree_operations.rb', line 104 def worktree_add(dir, commitish = nil) args = [dir] args << commitish unless commitish.nil? Git::Commands::Worktree::Add.new(@execution_context).call(*args).stdout end |
#worktree_list ⇒ Array<Git::WorktreeInfo>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns every worktree attached to the repository
Lists the main worktree first, then each linked worktree, in the order git reports them. The main worktree of a bare repository is included with WorktreeInfo#bare? true and no head or branch.
44 45 46 47 |
# File 'lib/git/repository/worktree_operations.rb', line 44 def worktree_list result = Git::Commands::Worktree::List.new(@execution_context).call(porcelain: true) Git::Parsers::Worktree.parse_list(result.stdout) end |
#worktree_lock(worktree, opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lock a linked worktree so that git worktree prune leaves it alone
Lock a worktree whose directory is on removable media or a network share that is not always mounted.
194 195 196 |
# File 'lib/git/repository/worktree_operations.rb', line 194 def worktree_lock(worktree, opts = {}) Git::Commands::Worktree::Lock.new(@execution_context).call(worktree.to_s, **opts).stdout end |
#worktree_move(worktree, new_path, opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Move a linked worktree to a new location
162 163 164 |
# File 'lib/git/repository/worktree_operations.rb', line 162 def worktree_move(worktree, new_path, opts = {}) Git::Commands::Worktree::Move.new(@execution_context).call(worktree.to_s, new_path, **opts).stdout end |
#worktree_prune ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prune stale worktree administrative files
Removes stale administrative files from $GIT_DIR/worktrees. A
worktree becomes stale when its directory no longer exists on disk.
261 262 263 |
# File 'lib/git/repository/worktree_operations.rb', line 261 def worktree_prune Git::Commands::Worktree::Prune.new(@execution_context).call.stdout end |
#worktree_remove(worktree) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remove a linked worktree
130 131 132 |
# File 'lib/git/repository/worktree_operations.rb', line 130 def worktree_remove(worktree) Git::Commands::Worktree::Remove.new(@execution_context).call(worktree.to_s).stdout end |
#worktree_repair(*paths) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Repair the links between the repository and its linked worktrees
With no paths, repairs the link from each linked worktree back to the repository, which is needed after the repository directory was moved. Given the current paths of linked worktrees that were moved without #worktree_move, also repairs the repository's links to them.
242 243 244 |
# File 'lib/git/repository/worktree_operations.rb', line 242 def worktree_repair(*paths) Git::Commands::Worktree::Repair.new(@execution_context).call(*paths.map(&:to_s)).stdout end |
#worktree_unlock(worktree) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Unlock a linked worktree
213 214 215 |
# File 'lib/git/repository/worktree_operations.rb', line 213 def worktree_unlock(worktree) Git::Commands::Worktree::Unlock.new(@execution_context).call(worktree.to_s).stdout end |
#worktrees ⇒ Git::Worktrees
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #worktree_list instead
#worktree_list returns Array<Git::WorktreeInfo>. Look a worktree up
by path with worktree_list.find { |w| w.path == path } in place of
worktrees[path], and call #worktree_prune in place of
worktrees.prune. Calling this method emits one deprecation warning.
Return a Worktrees collection of all worktrees (main and linked)
The collection is populated eagerly when this method is called (git runs at construction time). It is enumerable and supports indexed access by worktree path.
330 331 332 333 334 335 336 |
# File 'lib/git/repository/worktree_operations.rb', line 330 def worktrees Git::Deprecation.warn( 'Git::Repository#worktrees is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#worktree_list instead.' ) Git::Worktrees.new(self) end |
#worktrees_all ⇒ Array<Array(String, String)>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use #worktree_list instead
#worktree_list returns one WorktreeInfo per worktree, with
path and head in place of the pair, and includes the main worktree
of a bare repository.
Returns all worktrees as an array of directory and SHA pairs
Lists the main worktree and all linked worktrees. The main worktree of a bare repository has no checked-out commit and is omitted.
76 77 78 79 80 81 82 |
# File 'lib/git/repository/worktree_operations.rb', line 76 def worktrees_all Git::Deprecation.warn( 'Git::Repository#worktrees_all is deprecated and will be removed in v6.0.0. ' \ 'Use Git::Repository#worktree_list instead.' ) worktree_list.reject { |worktree| worktree.head.nil? }.map { |worktree| [worktree.path, worktree.head] } end |