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
Included by Git::Repository.
Instance Method Summary collapse
-
#worktree(dir, commitish = nil) ⇒ Git::Worktree
private
Return a Worktree object for the given directory and optional commitish.
-
#worktree_add(dir, commitish = nil) ⇒ String
private
Create a new linked worktree at the given directory.
-
#worktree_prune ⇒ String
private
Prune stale worktree administrative files.
-
#worktree_remove(dir) ⇒ String
private
Remove a linked worktree.
-
#worktrees ⇒ Git::Worktrees
private
Return a Worktrees collection of all worktrees (main and linked).
-
#worktrees_all ⇒ Array<Array(String, String)>
private
Returns all worktrees as an array of directory and SHA pairs.
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.
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.
131 132 133 |
# File 'lib/git/repository/worktree_operations.rb', line 131 def worktree(dir, commitish = nil) 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
69 70 71 72 73 74 |
# File 'lib/git/repository/worktree_operations.rb', line 69 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_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.
109 110 111 |
# File 'lib/git/repository/worktree_operations.rb', line 109 def worktree_prune Git::Commands::Worktree::Prune.new(@execution_context).call.stdout end |
#worktree_remove(dir) ⇒ 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
90 91 92 |
# File 'lib/git/repository/worktree_operations.rb', line 90 def worktree_remove(dir) Git::Commands::Worktree::Remove.new(@execution_context).call(dir).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.
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.
154 155 156 |
# File 'lib/git/repository/worktree_operations.rb', line 154 def worktrees 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.
Returns all worktrees as an array of directory and SHA pairs
Lists all worktrees attached to the repository, including the main worktree and all linked worktrees.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/git/repository/worktree_operations.rb', line 35 def worktrees_all worktree_entries = [] current_directory = '' command_output = Git::Commands::Worktree::List.new(@execution_context).call(porcelain: true).stdout command_output.each_line(chomp: true) do |line| key, value = line.split(' ', 2) current_directory = value if key == 'worktree' worktree_entries << [current_directory, value] if key == 'HEAD' end worktree_entries end |