Class: Git::BranchInfo
- Inherits:
-
Data
- Object
- Data
- Git::BranchInfo
- Defined in:
- lib/git/branch_info.rb
Overview
Value object representing branch metadata from git branch output
This is a lightweight, immutable data structure returned by branch listing commands. It contains only the data parsed from git output without any repository context or operations.
Instance Attribute Summary collapse
-
#current ⇒ Boolean
readonly
Whether this branch is currently checked out in the current worktree.
-
#refname ⇒ String
readonly
The full reference name of the branch.
-
#symref ⇒ String?
readonly
The target reference if this is a symbolic reference.
-
#target_oid ⇒ String?
readonly
The commit object ID (SHA) that this branch points to.
-
#upstream ⇒ Git::BranchInfo?
readonly
The configured upstream/tracking branch.
-
#worktree ⇒ Boolean
readonly
Whether this branch is checked out in another linked worktree.
Instance Method Summary collapse
-
#current? ⇒ Boolean
True if this is the currently checked out branch.
-
#detached? ⇒ Boolean
Always false for BranchInfo (see DetachedHeadInfo for detached state).
-
#remote? ⇒ Boolean
True if this is a remote-tracking branch.
-
#remote_name ⇒ String?
The name of the remote (e.g., 'origin'), or nil for local branches.
-
#short_name ⇒ String
The branch name without remote prefix (e.g., 'main' or 'feature/foo').
-
#symref? ⇒ Boolean
True if this is a symbolic reference.
-
#to_s ⇒ String
String representation (the full refname).
-
#unborn? ⇒ Boolean
True if this is an unborn branch (no commits yet).
-
#worktree? ⇒ Boolean
True if this branch is checked out in another worktree.
Instance Attribute Details
#current ⇒ Boolean (readonly)
Whether this branch is currently checked out in the current worktree
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#refname ⇒ String (readonly)
The full reference name of the branch
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#symref ⇒ String? (readonly)
The target reference if this is a symbolic reference
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#target_oid ⇒ String? (readonly)
The commit object ID (SHA) that this branch points to
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#upstream ⇒ Git::BranchInfo? (readonly)
Remote-tracking branches (e.g., 'origin/main') have upstream: nil
When upstream exists but the remote-tracking branch hasn't been fetched, the upstream's target_oid may be nil
The configured upstream/tracking branch
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
#worktree ⇒ Boolean (readonly)
Whether this branch is checked out in another linked worktree
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/git/branch_info.rb', line 133 BranchInfo = Data.define(:refname, :target_oid, :current, :worktree, :symref, :upstream) do # @return [Boolean] always false for BranchInfo (see DetachedHeadInfo for detached state) def detached? = false # @return [Boolean] true if this is an unborn branch (no commits yet) def unborn? = target_oid.nil? # @return [Boolean] true if this is the currently checked out branch def current? = current # @return [Boolean] true if this branch is checked out in another worktree def worktree? = worktree # @return [Boolean] true if this is a symbolic reference def symref? = !symref.nil? # @return [Boolean] true if this is a remote-tracking branch def remote? = !remote_name.nil? # @return [String, nil] the name of the remote (e.g., 'origin'), or nil for local branches def remote_name parse_refname[:remote_name] end # @return [String] the branch name without remote prefix (e.g., 'main' or 'feature/foo') def short_name parse_refname[:branch_name] end # @return [String] string representation (the full refname) def to_s = refname private # Parse the refname and return match data # # The regex is guaranteed to match any non-empty string due to the `.+` pattern, # so we don't need nil checking. If refname is empty/nil, this would fail at # object creation time since refname is a required attribute. # # @return [MatchData] the match result def parse_refname refname.match(Git::BRANCH_REFNAME_REGEXP) end end |
Instance Method Details
#current? ⇒ Boolean
Returns true if this is the currently checked out branch.
141 |
# File 'lib/git/branch_info.rb', line 141 def current? = current |
#detached? ⇒ Boolean
Returns always false for BranchInfo (see DetachedHeadInfo for detached state).
135 |
# File 'lib/git/branch_info.rb', line 135 def detached? = false |
#remote? ⇒ Boolean
Returns true if this is a remote-tracking branch.
150 |
# File 'lib/git/branch_info.rb', line 150 def remote? = !remote_name.nil? |
#remote_name ⇒ String?
Returns the name of the remote (e.g., 'origin'), or nil for local branches.
153 154 155 |
# File 'lib/git/branch_info.rb', line 153 def remote_name parse_refname[:remote_name] end |
#short_name ⇒ String
Returns the branch name without remote prefix (e.g., 'main' or 'feature/foo').
158 159 160 |
# File 'lib/git/branch_info.rb', line 158 def short_name parse_refname[:branch_name] end |
#symref? ⇒ Boolean
Returns true if this is a symbolic reference.
147 |
# File 'lib/git/branch_info.rb', line 147 def symref? = !symref.nil? |
#to_s ⇒ String
Returns string representation (the full refname).
163 |
# File 'lib/git/branch_info.rb', line 163 def to_s = refname |
#unborn? ⇒ Boolean
Returns true if this is an unborn branch (no commits yet).
138 |
# File 'lib/git/branch_info.rb', line 138 def unborn? = target_oid.nil? |
#worktree? ⇒ Boolean
Returns true if this branch is checked out in another worktree.
144 |
# File 'lib/git/branch_info.rb', line 144 def worktree? = worktree |