Class: Hiiro::Git::Worktree
- Inherits:
-
Object
- Object
- Hiiro::Git::Worktree
- Defined in:
- lib/hiiro/git/worktree.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #bare? ⇒ Boolean
- #detached? ⇒ Boolean
-
#initialize(path:, head: nil, branch: nil, detached: false, bare: false) ⇒ Worktree
constructor
A new instance of Worktree.
- #match?(pwd) ⇒ Boolean
- #name ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(path:, head: nil, branch: nil, detached: false, bare: false) ⇒ Worktree
Returns a new instance of Worktree.
25 26 27 28 29 30 31 |
# File 'lib/hiiro/git/worktree.rb', line 25 def initialize(path:, head: nil, branch: nil, detached: false, bare: false) @path = path @head = head @branch = branch @detached = detached @bare = end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
4 5 6 |
# File 'lib/hiiro/git/worktree.rb', line 4 def branch @branch end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
4 5 6 |
# File 'lib/hiiro/git/worktree.rb', line 4 def head @head end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/hiiro/git/worktree.rb', line 4 def path @path end |
Class Method Details
.from_porcelain_block(lines) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hiiro/git/worktree.rb', line 6 def self.from_porcelain_block(lines) attrs = {} lines.each do |line| case line when /^worktree (.+)/ attrs[:path] = $1 when /^HEAD (.+)/ attrs[:head] = $1 when /^branch refs\/heads\/(.+)/ attrs[:branch] = $1 when 'detached' attrs[:detached] = true when 'bare' attrs[:bare] = true end end new(**attrs) if attrs[:path] end |
Instance Method Details
#bare? ⇒ Boolean
37 38 39 |
# File 'lib/hiiro/git/worktree.rb', line 37 def @bare end |
#detached? ⇒ Boolean
33 34 35 |
# File 'lib/hiiro/git/worktree.rb', line 33 def detached? @detached end |
#match?(pwd) ⇒ Boolean
45 46 47 |
# File 'lib/hiiro/git/worktree.rb', line 45 def match?(pwd) pwd == path || pwd.start_with?(path + '/') end |
#name ⇒ Object
41 42 43 |
# File 'lib/hiiro/git/worktree.rb', line 41 def name File.basename(path) end |
#to_h ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/hiiro/git/worktree.rb', line 49 def to_h { path: path, head: head, branch: branch, detached: detached?, bare: , }.compact end |