Class: RubyGit::Status::RenamedEntry
- Defined in:
- lib/ruby_git/status/renamed_entry.rb
Overview
Represents a renamed file in git status
Constant Summary
Constants inherited from Entry
Entry::RENAME_OPERATIONS, Entry::STATUS_CODES
Instance Attribute Summary collapse
-
#head_mode ⇒ Integer
readonly
The mode of the file in HEAD.
-
#head_sha ⇒ String
readonly
The SHA of this object in HEAD.
-
#index_mode ⇒ Integer
readonly
The mode of the file in the index.
-
#index_sha ⇒ String
readonly
The SHA of this object in the index.
-
#index_status ⇒ Symbol
readonly
The status in the staging area.
-
#operation ⇒ String
readonly
The operation that was performed on the file: 'R' for or 'C' for copy).
-
#original_path ⇒ String
readonly
The original path before rename.
-
#path ⇒ String
readonly
The path after the rename.
-
#similarity ⇒ Integer
readonly
The similarity index between the original and renamed file.
-
#similarity_score ⇒ Integer
readonly
The similarity index between the original and renamed file.
-
#worktree_mode ⇒ Integer
readonly
The mode of the file in the worktree.
-
#worktree_status ⇒ Symbol
readonly
The status in the worktree.
Class Method Summary collapse
-
.parse(line) ⇒ RubyGit::Status::RenamedEntry
Parse a git status line to create a renamed entry.
Instance Method Summary collapse
-
#initialize(index_status:, worktree_status:, submodule_status:, head_mode:, index_mode:, worktree_mode:, head_sha:, index_sha:, operation:, similarity_score:, path:, original_path:) ⇒ RenamedEntry
constructor
Initialize a new renamed entry.
-
#staged? ⇒ Boolean
Does the entry have staged changes in the index?.
-
#unstaged? ⇒ Boolean
Does the entry have unstaged changes in the worktree?.
Methods inherited from Entry
#fully_staged?, #ignored?, rename_operation_to_symbol, status_to_symbol, #unmerged?, #untracked?
Constructor Details
#initialize(index_status:, worktree_status:, submodule_status:, head_mode:, index_mode:, worktree_mode:, head_sha:, index_sha:, operation:, similarity_score:, path:, original_path:) ⇒ RenamedEntry
Initialize a new renamed entry
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 210 def initialize( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists index_status:, worktree_status:, submodule_status:, head_mode:, index_mode:, worktree_mode:, head_sha:, index_sha:, operation:, similarity_score:, path:, original_path: ) super(path) @index_status = index_status @worktree_status = worktree_status @submodule_status = submodule_status @head_mode = head_mode @index_mode = index_mode @worktree_mode = worktree_mode @head_sha = head_sha @index_sha = index_sha @operation = operation @similarity = similarity_score @original_path = original_path end |
Instance Attribute Details
#head_mode ⇒ Integer (readonly)
The mode of the file in HEAD
45 46 47 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 45 def head_mode @head_mode end |
#head_sha ⇒ String (readonly)
The SHA of this object in HEAD
81 82 83 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 81 def head_sha @head_sha end |
#index_mode ⇒ Integer (readonly)
The mode of the file in the index
57 58 59 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 57 def index_mode @index_mode end |
#index_sha ⇒ String (readonly)
The SHA of this object in the index
93 94 95 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 93 def index_sha @index_sha end |
#index_status ⇒ Symbol (readonly)
The status in the staging area
21 22 23 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 21 def index_status @index_status end |
#operation ⇒ String (readonly)
The operation that was performed on the file: 'R' for or 'C' for copy)
105 106 107 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 105 def operation @operation end |
#original_path ⇒ String (readonly)
The original path before rename
141 142 143 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 141 def original_path @original_path end |
#path ⇒ String (readonly)
The path after the rename
129 130 131 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 129 def path @path end |
#similarity ⇒ Integer (readonly)
The similarity index between the original and renamed file
117 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 117 attr_reader :similarity_score |
#similarity_score ⇒ Integer (readonly)
The similarity index between the original and renamed file
117 118 119 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 117 def similarity_score @similarity_score end |
#worktree_mode ⇒ Integer (readonly)
The mode of the file in the worktree
69 70 71 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 69 def worktree_mode @worktree_mode end |
#worktree_status ⇒ Symbol (readonly)
The status in the worktree
33 34 35 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 33 def worktree_status @worktree_status end |
Class Method Details
.parse(line) ⇒ RubyGit::Status::RenamedEntry
Parse a git status line to create a renamed entry
The line is expected to be in porcelain v2 format with NUL terminators.
The format is as follows:
2
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 159 def self.parse(line) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength tokens = line.split(' ', 10) path, original_path = tokens[9].split("\0") new( index_status: Entry.status_to_symbol(tokens[1][0]), worktree_status: Entry.status_to_symbol(tokens[1][1]), submodule_status: SubmoduleStatus.parse(tokens[2]), head_mode: Integer(tokens[3], 8), index_mode: Integer(tokens[4], 8), worktree_mode: Integer(tokens[5], 8), head_sha: tokens[6], index_sha: tokens[7], operation: Entry.rename_operation_to_symbol(tokens[8][0]), similarity_score: tokens[8][1..].to_i, path: path, original_path: original_path ) end |
Instance Method Details
#staged? ⇒ Boolean
Does the entry have staged changes in the index?
- An entry can have both staged and unstaged changes
252 253 254 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 252 def staged? index_status != :unmodified end |
#unstaged? ⇒ Boolean
Does the entry have unstaged changes in the worktree?
- An entry can have both staged and unstaged changes
- All untracked entries are considered unstaged
241 242 243 |
# File 'lib/ruby_git/status/renamed_entry.rb', line 241 def unstaged? worktree_status != :unmodified end |