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.
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
43 44 45 46 47 48 49 |
# File 'lib/git/worktree.rb', line 43 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
29 30 31 |
# File 'lib/git/worktree.rb', line 29 def dir @dir end |
#full ⇒ String
Full worktree descriptor including the optional commitish
23 24 25 |
# File 'lib/git/worktree.rb', line 23 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.
90 91 92 |
# File 'lib/git/worktree.rb', line 90 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.
72 73 74 75 |
# File 'lib/git/worktree.rb', line 72 def gcommit @gcommit ||= worktree_repository.gcommit(@full) @gcommit end |
#remove ⇒ String
Removes this worktree from disk
Runs git worktree remove for #dir.
105 106 107 |
# File 'lib/git/worktree.rb', line 105 def remove worktree_repository.worktree_remove(@dir) end |
#to_a ⇒ Array<String>
Returns an array containing the full worktree descriptor
116 117 118 |
# File 'lib/git/worktree.rb', line 116 def to_a [@full] end |
#to_s ⇒ String
Returns the full worktree descriptor as a string
127 128 129 |
# File 'lib/git/worktree.rb', line 127 def to_s @full end |