Class: RubyGit::Status::OrdinaryEntry

Inherits:
Entry
  • Object
show all
Defined in:
lib/ruby_git/status/ordinary_entry.rb

Overview

Represents an ordinary changed file in git status

Constant Summary

Constants inherited from Entry

Entry::RENAME_OPERATIONS, Entry::STATUS_CODES

Instance Attribute Summary collapse

Attributes inherited from Entry

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entry

#fully_staged?, #ignored?, rename_operation_to_symbol, status_to_symbol, #unmerged?, #untracked?

Constructor Details

#initialize(path:, index_status:, worktree_status:, submodule_status:, head_mode:, index_mode:, worktree_mode:, head_sha:, index_sha:) ⇒ OrdinaryEntry

Initialize a new ordinary entry

Examples:

path = 'lib/example.rb'
index_status = :modified
worktree_status = :modified
submodule_status = nil
worktree_mode = 0o100644
index_mode = 0o100644
head_mode = 0o100644
head_sha = 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'
index_sha = 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'
OrdinaryEntry.new(
  path:, index_status:, worktree_status:, submodule_status:,
  worktree_mode:, index_mode:, head_mode:, head_sha:, index_sha:
)

Parameters:

  • path (String)

    file path

  • index_status (Symbol)

    status in staging area

  • worktree_status (Symbol)

    status in worktree

  • submodule_status (SubmoduleStatus, nil)

    submodule status if applicable

  • worktree_mode (Integer)

    file mode in worktree

  • index_mode (Integer)

    file mode in staging area

  • head_mode (Integer)

    file mode in HEAD



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/ruby_git/status/ordinary_entry.rb', line 165

def initialize( # rubocop:disable Metrics/ParameterLists
  path:,
  index_status:, worktree_status:,
  submodule_status:,
  head_mode:, index_mode:, worktree_mode:,
  head_sha:, index_sha:
)
  super(path)
  @index_status = index_status
  @worktree_status = worktree_status
  @submodule_status = submodule_status
  @worktree_mode = worktree_mode
  @index_mode = index_mode
  @head_mode = head_mode
  @head_sha = head_sha
  @index_sha = index_sha
end

Instance Attribute Details

#head_modeInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The file mode in HEAD

Examples:

entry.head_mode #=> 0o100644

Returns:

  • (Integer)

    file mode in HEAD



82
83
84
# File 'lib/ruby_git/status/ordinary_entry.rb', line 82

def head_mode
  @head_mode
end

#head_shaString (readonly)

The SHA of this object in HEAD

Examples:

entry.head_sha #=> 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'

Returns:

  • (String)

    SHA of this object in HEAD



58
59
60
# File 'lib/ruby_git/status/ordinary_entry.rb', line 58

def head_sha
  @head_sha
end

#index_modeInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The file mode in the index

Examples:

entry.index_mode #=> 0o100644

Returns:

  • (Integer)

    file mode in the index



94
95
96
# File 'lib/ruby_git/status/ordinary_entry.rb', line 94

def index_mode
  @index_mode
end

#index_shaString (readonly)

The SHA of this object in the index

Examples:

entry.index_sha #=> 'd670460b4b4aece5915caf5c68d12f560a9fe3e4'

Returns:

  • (String)

    SHA of this object in the index



70
71
72
# File 'lib/ruby_git/status/ordinary_entry.rb', line 70

def index_sha
  @index_sha
end

#index_statusSymbol (readonly)

The status in the staging area

Examples:

entry.index_status #=> :modified

Returns:

  • (Symbol)

    staging status



22
23
24
# File 'lib/ruby_git/status/ordinary_entry.rb', line 22

def index_status
  @index_status
end

#submodule_statusSubmoduleStatus? (readonly)

The submodule status if the entry is a submodule

Examples:

entry.submodule #=> 'N...'

Returns:



46
47
48
# File 'lib/ruby_git/status/ordinary_entry.rb', line 46

def submodule_status
  @submodule_status
end

#worktree_modeInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The file mode in the worktree

Examples:

entry.worktree_mode #=> 0o100644

Returns:

  • (Integer)

    file mode in the worktree



106
107
108
# File 'lib/ruby_git/status/ordinary_entry.rb', line 106

def worktree_mode
  @worktree_mode
end

#worktree_statusSymbol (readonly)

The status in the worktree

Examples:

entry.worktree_status #=> :modified

Returns:

  • (Symbol)

    worktree status



34
35
36
# File 'lib/ruby_git/status/ordinary_entry.rb', line 34

def worktree_status
  @worktree_status
end

Class Method Details

.parse(line) ⇒ RubyGit::Status::OrdinaryEntry

Parse an ordinary change line of git status output

The line is expected to be in porcelain v2 format with NUL terminators.

The format is as follows: 1

Examples:

line = '1 M N... 100644 100644 100644 d670460b4b4aece5915caf5c68d12f560a9fe3e4 ' \
  \d670460b4b4aece5915caf5c68d12f560a9fe3e4 lib/example.rb'
OrdinaryEntry.parse(line) #=> #<RubyGit::Status::OrdinaryEntry:0x00000001046bd488 ...>

Parameters:

  • line (String)

    line from git status

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ruby_git/status/ordinary_entry.rb', line 124

def self.parse(line) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  tokens = line.split

  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],
    path: tokens[8]
  )
end

Instance Method Details

#staged?Boolean

Does the entry have staged changes in the index?

  • An entry can have both staged and unstaged changes

Examples:

entry.ignored? #=> false

Returns:

  • (Boolean)


202
203
204
# File 'lib/ruby_git/status/ordinary_entry.rb', line 202

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

Examples:

entry.ignored? #=> false

Returns:

  • (Boolean)


191
192
193
# File 'lib/ruby_git/status/ordinary_entry.rb', line 191

def unstaged?
  worktree_status != :unmodified
end