Class: Git::WorktreeInfo
- Inherits:
-
Data
- Object
- Data
- Git::WorktreeInfo
- Defined in:
- lib/git/worktree_info.rb
Overview
Immutable value object for one entry of git worktree list
Each entry carries what git worktree list --porcelain reports for a
worktree: its path, the checked-out HEAD and branch, and whether it is bare,
detached, locked, or prunable, with the reason git gives for the last two.
Instance Attribute Summary collapse
-
#bare ⇒ Boolean
readonly
True if this is the main worktree of a bare repository.
-
#branch ⇒ String?
readonly
The full refname of the checked-out branch (e.g., 'refs/heads/main'), or nil when the worktree is bare or detached.
-
#detached ⇒ Boolean
readonly
True if HEAD is detached in this worktree.
-
#head ⇒ String?
readonly
The full object ID of the checked-out HEAD commit (the all-zero object ID when the branch has no commits yet), or nil for a bare main worktree.
-
#lock_reason ⇒ String?
readonly
The reason given when the worktree was locked, or nil when it is not locked or was locked without a reason.
-
#locked ⇒ Boolean
readonly
True if the worktree is locked.
-
#path ⇒ String
readonly
The worktree directory as git reports it.
-
#prunable ⇒ Boolean
readonly
True if
git worktree prunewould remove this entry. -
#prune_reason ⇒ String?
readonly
Git's explanation of why the entry is prunable, or nil when it is not prunable.
Instance Method Summary collapse
-
#bare? ⇒ Boolean
Whether this is the main worktree of a bare repository.
-
#detached? ⇒ Boolean
Whether HEAD is detached in this worktree.
-
#locked? ⇒ Boolean
Whether the worktree is locked.
-
#prunable? ⇒ Boolean
Whether
git worktree prunewould remove this entry. -
#to_s ⇒ String
Returns the worktree path.
Instance Attribute Details
#bare ⇒ Boolean (readonly)
Returns true if this is the main worktree of a bare repository.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#branch ⇒ String? (readonly)
Returns the full refname of the checked-out branch (e.g., 'refs/heads/main'), or nil when the worktree is bare or detached.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#detached ⇒ Boolean (readonly)
Returns true if HEAD is detached in this worktree.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#head ⇒ String? (readonly)
Returns the full object ID of the checked-out HEAD commit (the all-zero object ID when the branch has no commits yet), or nil for a bare main worktree.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#lock_reason ⇒ String? (readonly)
Returns the reason given when the worktree was locked, or nil when it is not locked or was locked without a reason.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#locked ⇒ Boolean (readonly)
Returns true if the worktree is locked.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#path ⇒ String (readonly)
Returns the worktree directory as git reports it.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#prunable ⇒ Boolean (readonly)
Returns true if git worktree prune would remove this entry.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
#prune_reason ⇒ String? (readonly)
Returns git's explanation of why the entry is prunable, or nil when it is not prunable.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/git/worktree_info.rb', line 72 WorktreeInfo = Data.define( :path, :head, :branch, :bare, :detached, :locked, :lock_reason, :prunable, :prune_reason ) do # Whether this is the main worktree of a bare repository # # @example # info.bare? # => false # # @return [Boolean] true if the worktree is bare def = # Whether HEAD is detached in this worktree # # @example # info.detached? # => false # # @return [Boolean] true if HEAD is detached def detached? = detached # Whether the worktree is locked # # @example # info.locked? # => true # # @return [Boolean] true if the worktree is locked def locked? = locked # Whether `git worktree prune` would remove this entry # # @example # info.prunable? # => false # # @return [Boolean] true if the entry is prunable def prunable? = prunable # Returns the worktree path # # Lets an entry be passed directly to the worktree operations that take a # path, such as {Git::Repository::WorktreeOperations#worktree_remove}. # # @example Convert to string # info.to_s # => '/tmp/wt/linked' # # @return [String] the worktree path def to_s path end end |
Instance Method Details
#bare? ⇒ Boolean
Whether this is the main worktree of a bare repository
89 |
# File 'lib/git/worktree_info.rb', line 89 def = |
#detached? ⇒ Boolean
Whether HEAD is detached in this worktree
97 |
# File 'lib/git/worktree_info.rb', line 97 def detached? = detached |
#locked? ⇒ Boolean
Whether the worktree is locked
105 |
# File 'lib/git/worktree_info.rb', line 105 def locked? = locked |
#prunable? ⇒ Boolean
Whether git worktree prune would remove this entry
113 |
# File 'lib/git/worktree_info.rb', line 113 def prunable? = prunable |
#to_s ⇒ String
Returns the worktree path
Lets an entry be passed directly to the worktree operations that take a path, such as Repository::WorktreeOperations#worktree_remove.
124 125 126 |
# File 'lib/git/worktree_info.rb', line 124 def to_s path end |