Class: Git::Worktree
- Inherits:
-
Object
- Object
- Git::Worktree
- Defined in:
- lib/git/worktree.rb
Overview
A worktree in a Git repository
Represents a single linked or main worktree. Constructed by Repository::WorktreeOperations#worktree or populated by Worktrees.
Accepts either a Repository (new form) or a Base (legacy form)
as the base argument. The is_a?(Git::Base) guard routes git operations
through the facade repository and will be removed when Base is
deleted in Phase 4.
Instance Attribute Summary collapse
-
#dir ⇒ String
Filesystem path of this worktree.
-
#full ⇒ String
Full worktree descriptor including the optional commitish.
Instance Method Summary collapse
-
#add ⇒ String
Creates this worktree on disk.
-
#gcommit ⇒ Git::Object::Commit, String
Returns the commit (or commitish string) associated with this worktree.
-
#initialize(base, dir, gcommit = nil)
constructor
Creates a new Worktree object.
-
#remove ⇒ String
Removes this worktree from disk.
-
#to_a ⇒ Array<String>
Returns an array containing the full worktree descriptor.
-
#to_s ⇒ String
Returns the full worktree descriptor as a string.
Constructor Details
#initialize(base, dir, gcommit = nil)
Creates a new Worktree object
50 51 52 53 54 55 56 |
# File 'lib/git/worktree.rb', line 50 def initialize(base, dir, gcommit = nil) @full = dir @full += " #{gcommit}" unless gcommit.nil? @base = base @dir = dir @gcommit = gcommit end |
Instance Attribute Details
#dir ⇒ String
Filesystem path of this worktree
36 37 38 |
# File 'lib/git/worktree.rb', line 36 def dir @dir end |
#full ⇒ String
Full worktree descriptor including the optional commitish
30 31 32 |
# File 'lib/git/worktree.rb', line 30 def full @full end |
Instance Method Details
#add ⇒ String
Creates this worktree on disk
Runs git worktree add for #dir, optionally at the commitish passed
at construction time.
97 98 99 |
# File 'lib/git/worktree.rb', line 97 def add worktree_repository.worktree_add(@dir, @gcommit) end |
#gcommit ⇒ Git::Object::Commit, String
Returns the commit (or commitish string) associated with this worktree
When a commitish string was supplied at construction time (e.g. by
Git::Worktrees which passes the raw SHA from git worktree list), that
string is returned as-is. Otherwise the value is lazily resolved on first
call via worktree_repository.gcommit(@full) and the result is memoized.
79 80 81 82 |
# File 'lib/git/worktree.rb', line 79 def gcommit @gcommit ||= worktree_repository.gcommit(@full) @gcommit end |
#remove ⇒ String
Removes this worktree from disk
Runs git worktree remove for #dir.
112 113 114 |
# File 'lib/git/worktree.rb', line 112 def remove worktree_repository.worktree_remove(@dir) end |
#to_a ⇒ Array<String>
Returns an array containing the full worktree descriptor
123 124 125 |
# File 'lib/git/worktree.rb', line 123 def to_a [@full] end |
#to_s ⇒ String
Returns the full worktree descriptor as a string
134 135 136 |
# File 'lib/git/worktree.rb', line 134 def to_s @full end |