Class: Git::StatusFileInfo
- Inherits:
-
Data
- Object
- Data
- Git::StatusFileInfo
- Defined in:
- lib/git/status_file_info.rb
Overview
Immutable value object for the status of one path in the index and working tree
Each member holds one field of the entry git status --porcelain=v2 reports
for the path. index_status and worktree_status are the X and Y
characters of that entry: . unmodified, M modified, T type changed, A
added, D deleted, R renamed, C copied, or U unmerged. Untracked
entries carry ? in both and ignored entries carry ! in both, mirroring
the ?? and !! codes of the short status format.
The mode and SHA members are nil for untracked and ignored entries. For
unmerged entries the per-stage modes and SHAs live in unmerged_stages and
mode_head, mode_index, sha_head, and sha_index are nil.
original_path and rename_score are set only for rename and copy entries.
The predicates follow these rules: added? when index_status is A,
deleted? when either status is D, changed? when either status is M
or T, renamed? when either status is R, untracked? and ignored?
from the ? and ! codes, and unmerged? when unmerged_stages is set.
Every String member is a frozen copy of the value given, and
unmerged_stages is a deeply frozen copy, so an entry cannot be changed
through a member the caller still references.
Instance Attribute Summary collapse
-
#index_status ⇒ String
readonly
The
Xstatus character (HEAD versus index),?for untracked and!for ignored entries. -
#mode_head ⇒ String?
readonly
The octal file mode in HEAD (
000000when the path is not in HEAD), ornilfor untracked, ignored, and unmerged entries. -
#mode_index ⇒ String?
readonly
The octal file mode in the index (
000000when the path is not in the index), ornilfor untracked, ignored, and unmerged entries. -
#mode_worktree ⇒ String?
readonly
The octal file mode in the working tree (
000000when the path is not in the working tree), ornilfor untracked and ignored entries. -
#original_path ⇒ String?
readonly
The path the entry was renamed or copied from, or
nilfor every other entry. -
#path ⇒ String
readonly
The repository-relative path.
-
#rename_score ⇒ Integer?
readonly
The similarity score of a rename or copy entry, or
nilfor every other entry. -
#sha_head ⇒ String?
readonly
The object name of the blob in HEAD (all zeros when the path is not in HEAD), or
nilfor untracked, ignored, and unmerged entries. -
#sha_index ⇒ String?
readonly
The object name of the blob in the index (all zeros when the path is not in the index), or
nilfor untracked, ignored, and unmerged entries. -
#submodule ⇒ String?
readonly
The four-character submodule state (
N...for a regular file), ornilfor untracked and ignored entries. -
#unmerged_stages ⇒ Hash{Integer => Hash{Symbol => String}}?
readonly
The mode and SHA of each conflict stage keyed by stage number (1 for the merge base, 2 for "ours", 3 for "theirs"), as frozen
\\{ mode:, sha: }hashes, ornilfor every other entry. -
#worktree_status ⇒ String
readonly
The
Ystatus character (index versus working tree),?for untracked and!for ignored entries.
Instance Method Summary collapse
-
#added? ⇒ Boolean
Returns
truewhen the path was added to the index and is not in HEAD. -
#changed? ⇒ Boolean
Returns
truewhen the path's content or type changed in the index or working tree. -
#deleted? ⇒ Boolean
Returns
truewhen the path was deleted from the index or working tree. -
#ignored? ⇒ Boolean
Returns
truewhen the path is ignored. -
#initialize(**members) ⇒ StatusFileInfo
constructor
Creates a file status value object holding frozen copies of its members.
-
#renamed? ⇒ Boolean
Returns
truewhen the path was renamed in the index or working tree. -
#unmerged? ⇒ Boolean
Returns
truewhen the path has merge conflicts. -
#untracked? ⇒ Boolean
Returns
truewhen the path is not tracked by git.
Constructor Details
#initialize(**members) ⇒ StatusFileInfo
Creates a file status value object holding frozen copies of its members
String members are duplicated and frozen, and unmerged_stages is
duplicated and frozen down to its mode and SHA strings, so neither this
value nor a Git::StatusInfo holding it can be changed through a member
the caller still references.
170 171 172 |
# File 'lib/git/status_file_info.rb', line 170 def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end |
Instance Attribute Details
#index_status ⇒ String (readonly)
Returns the X status character (HEAD versus index), ? for
untracked and ! for ignored entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#mode_head ⇒ String? (readonly)
Returns the octal file mode in HEAD (000000 when the path
is not in HEAD), or nil for untracked, ignored, and unmerged entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#mode_index ⇒ String? (readonly)
Returns the octal file mode in the index (000000 when the
path is not in the index), or nil for untracked, ignored, and unmerged
entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#mode_worktree ⇒ String? (readonly)
Returns the octal file mode in the working tree (000000
when the path is not in the working tree), or nil for untracked and
ignored entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#original_path ⇒ String? (readonly)
Returns the path the entry was renamed or copied from, or
nil for every other entry.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#path ⇒ String (readonly)
Returns the repository-relative path.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#rename_score ⇒ Integer? (readonly)
Returns the similarity score of a rename or copy entry, or
nil for every other entry.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#sha_head ⇒ String? (readonly)
Returns the object name of the blob in HEAD (all zeros when
the path is not in HEAD), or nil for untracked, ignored, and unmerged
entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#sha_index ⇒ String? (readonly)
Returns the object name of the blob in the index (all zeros
when the path is not in the index), or nil for untracked, ignored, and
unmerged entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#submodule ⇒ String? (readonly)
Returns the four-character submodule state (N... for a
regular file), or nil for untracked and ignored entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#unmerged_stages ⇒ Hash{Integer => Hash{Symbol => String}}? (readonly)
Returns the mode and SHA of
each conflict stage keyed by stage number (1 for the merge base, 2 for
"ours", 3 for "theirs"), as frozen \\{ mode:, sha: } hashes, or nil
for every other entry.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
#worktree_status ⇒ String (readonly)
Returns the Y status character (index versus working tree), ?
for untracked and ! for ignored entries.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/git/status_file_info.rb', line 118 StatusFileInfo = Data.define( :path, :index_status, :worktree_status, :submodule, :mode_head, :mode_index, :mode_worktree, :sha_head, :sha_index, :original_path, :rename_score, :unmerged_stages ) do # Creates a file status value object holding frozen copies of its members # # String members are duplicated and frozen, and `unmerged_stages` is # duplicated and frozen down to its mode and SHA strings, so neither this # value nor a {Git::StatusInfo} holding it can be changed through a member # the caller still references. # # @example Build an entry from parsed fields # Git::StatusFileInfo.new(path: 'lib/foo.rb', index_status: 'M', worktree_status: '.', ...) # # @param members [Hash{Symbol => Object}] one value per member; every # member is required # # @option members [String] :path the repository-relative path # # @option members [String] :index_status the `X` status character # # @option members [String] :worktree_status the `Y` status character # # @option members [String, nil] :submodule the four-character submodule state # # @option members [String, nil] :mode_head the octal file mode in HEAD # # @option members [String, nil] :mode_index the octal file mode in the index # # @option members [String, nil] :mode_worktree the octal file mode in the working tree # # @option members [String, nil] :sha_head the object name of the blob in HEAD # # @option members [String, nil] :sha_index the object name of the blob in the index # # @option members [String, nil] :original_path the path a rename or copy came from # # @option members [Integer, nil] :rename_score the similarity score of a rename or copy # # @option members [Hash{Integer => Hash{Symbol => String}}, nil] :unmerged_stages # the mode and SHA of each conflict stage keyed by stage number # def initialize(**members) super(**members.transform_values { |value| deep_frozen(value) }) end # Returns `true` when the path is not tracked by git # # @example Check an untracked path # repo.status_info['new.rb'].untracked? #=> true # # @return [Boolean] `true` when both status characters are `?` # def untracked? = index_status == '?' && worktree_status == '?' # Returns `true` when the path is ignored # # Ignored entries are reported only when `git status` runs with `--ignored`. # {Git::Repository#status_info} does not pass that option, so this is # `false` for every entry it returns. # # @example Check an ignored entry # file = Git::Parsers::Status.parse("! tmp/debug.log\0").first # file.ignored? #=> true # # @return [Boolean] `true` when both status characters are `!` # def ignored? = index_status == '!' && worktree_status == '!' # Returns `true` when the path has merge conflicts # # @example Check a conflicted path # repo.status_info['lib/conflict.rb'].unmerged? #=> true # # @return [Boolean] `true` when `unmerged_stages` is set # def unmerged? = !unmerged_stages.nil? # Returns `true` when the path was renamed in the index or working tree # # @example Check a renamed path # repo.status_info['lib/new_name.rb'].renamed? #=> true # # @return [Boolean] `true` when either status character is `R` # def renamed? = index_status == 'R' || worktree_status == 'R' # Returns `true` when the path was added to the index and is not in HEAD # # @example Check a newly staged path # repo.status_info['lib/new.rb'].added? #=> true # # @return [Boolean] `true` when `index_status` is `A` # def added? = index_status == 'A' # Returns `true` when the path was deleted from the index or working tree # # @example Check a deleted path # repo.status_info['lib/old.rb'].deleted? #=> true # # @return [Boolean] `true` when either status character is `D` # def deleted? = index_status == 'D' || worktree_status == 'D' # Returns `true` when the path's content or type changed in the index or working tree # # @example Check a modified path # repo.status_info['lib/foo.rb'].changed? #=> true # # @return [Boolean] `true` when either status character is `M` or `T` # def changed? = [index_status, worktree_status].intersect?(%w[M T]) private # Returns a frozen copy of `value`, freezing the contents of a Hash recursively # # @param value [Object] a member value # # @return [Object] a frozen copy of a String or Hash; any other value as given # def deep_frozen(value) case value when String then value.dup.freeze when Hash then value.to_h { |key, item| [key, deep_frozen(item)] }.freeze else value end end end |
Instance Method Details
#added? ⇒ Boolean
Returns true when the path was added to the index and is not in HEAD
222 |
# File 'lib/git/status_file_info.rb', line 222 def added? = index_status == 'A' |
#changed? ⇒ Boolean
Returns true when the path's content or type changed in the index or working tree
240 |
# File 'lib/git/status_file_info.rb', line 240 def changed? = [index_status, worktree_status].intersect?(%w[M T]) |
#deleted? ⇒ Boolean
Returns true when the path was deleted from the index or working tree
231 |
# File 'lib/git/status_file_info.rb', line 231 def deleted? = index_status == 'D' || worktree_status == 'D' |
#ignored? ⇒ Boolean
Returns true when the path is ignored
Ignored entries are reported only when git status runs with --ignored.
Repository#status_info does not pass that option, so this is
false for every entry it returns.
195 |
# File 'lib/git/status_file_info.rb', line 195 def ignored? = index_status == '!' && worktree_status == '!' |
#renamed? ⇒ Boolean
Returns true when the path was renamed in the index or working tree
213 |
# File 'lib/git/status_file_info.rb', line 213 def renamed? = index_status == 'R' || worktree_status == 'R' |
#unmerged? ⇒ Boolean
Returns true when the path has merge conflicts
204 |
# File 'lib/git/status_file_info.rb', line 204 def unmerged? = !unmerged_stages.nil? |
#untracked? ⇒ Boolean
Returns true when the path is not tracked by git
181 |
# File 'lib/git/status_file_info.rb', line 181 def untracked? = index_status == '?' && worktree_status == '?' |