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_add(dir, commitish = nil) ⇒ Git::WorktreeInfo
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.
Instance Method Details
#worktree_add(dir, commitish = nil) ⇒ 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.
When commitish is nil and git creates the branch, it does so
before it creates the worktree, so a failure after that point leaves
the new branch in place without a worktree. A branch that already
existed is left as it was.
Create a new linked worktree at the given directory
Returns the entry that #worktree_list reports for the new worktree.
Its path is the directory as git records it: absolute, with symlinks
resolved, so /tmp/feature on macOS comes back as
/private/tmp/feature.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/git/repository/worktree_operations.rb', line 86 def worktree_add(dir, commitish = nil) args = [dir] args << commitish unless commitish.nil? Git::Commands::Worktree::Add.new(@execution_context).call(*args) # git records the path as given with symlinks resolved, so compare by # identity rather than by string: this covers symlinks, case-insensitive # filesystems, and Unicode normalization on macOS worktree_list.find { |worktree| File.identical?(worktree.path, dir) } || raise(Git::UnexpectedResultError, "worktree was created but not found in the worktree list: #{dir}") 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.
42 43 44 45 |
# File 'lib/git/repository/worktree_operations.rb', line 42 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.
182 183 184 |
# File 'lib/git/repository/worktree_operations.rb', line 182 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
150 151 152 |
# File 'lib/git/repository/worktree_operations.rb', line 150 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.
247 248 249 |
# File 'lib/git/repository/worktree_operations.rb', line 247 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
118 119 120 |
# File 'lib/git/repository/worktree_operations.rb', line 118 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.
228 229 230 |
# File 'lib/git/repository/worktree_operations.rb', line 228 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
201 202 203 |
# File 'lib/git/repository/worktree_operations.rb', line 201 def worktree_unlock(worktree) Git::Commands::Worktree::Unlock.new(@execution_context).call(worktree.to_s).stdout end |