Class: RubyGit::Status::Entry

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

Overview

Base class for git status entries

Constant Summary collapse

STATUS_CODES =

Status code mapping to symbols

{
  '.': :unmodified,
  M: :modified,
  T: :type_changed,
  A: :added,
  D: :deleted,
  R: :renamed,
  C: :copied,
  U: :updated_but_unmerged,
  '?': :untracked,
  '!': :ignored
}.freeze
RENAME_OPERATIONS =

Rename operation mapping to symbols

{
  'R' => :rename
  # git status doesn't actually try to detect copies
  # 'C' => :copy
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Entry

Initialize a new entry

Examples:

Entry.new('lib/example.rb')

Parameters:

  • path (String)

    file path



48
49
50
# File 'lib/ruby_git/status/entry.rb', line 48

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathString (readonly)

The path of the file

Examples:

entry.path #=> 'lib/example.rb'

Returns:

  • (String)

    file path



39
40
41
# File 'lib/ruby_git/status/entry.rb', line 39

def path
  @path
end

Class Method Details

.rename_operation_to_symbol(code) ⇒ Symbol

Convert a rename operation to a symbol

Examples:

Entry.rename_operation_to_symbol('R') #=> :rename

Parameters:

  • code (String)

    the operation code

Returns:

  • (Symbol)

    operation as symbol



72
73
74
# File 'lib/ruby_git/status/entry.rb', line 72

def self.rename_operation_to_symbol(code)
  RENAME_OPERATIONS[code] || :unknown
end

.status_to_symbol(code) ⇒ Symbol

Convert a status code to a symbol

Examples:

Entry.status_to_symbol('M') #=> :modified

Parameters:

  • code (String)

    status code

Returns:

  • (Symbol)

    status as symbol



60
61
62
# File 'lib/ruby_git/status/entry.rb', line 60

def self.status_to_symbol(code)
  STATUS_CODES[code.to_sym] || :unknown
end

Instance Method Details

#fully_staged?Boolean

Does the entry have staged changes in the index with no unstaged changes?

  • An entry can have both staged and unstaged changes

Examples:

entry.fully_staged? #=> false

Returns:

  • (Boolean)


148
# File 'lib/ruby_git/status/entry.rb', line 148

def fully_staged? = staged? && !unstaged?

#ignored?Boolean

Is the entry an ignored file?

  • Ignored entries are not considered untracked

Examples:

entry.ignored? #=> false

Returns:

  • (Boolean)


103
# File 'lib/ruby_git/status/entry.rb', line 103

def ignored? = false

#index_statusSymbol?

Get the staging status

Examples:

entry.staging_status #=> :modified

Returns:

  • (Symbol, nil)

    staging status symbol or nil if not applicable



83
# File 'lib/ruby_git/status/entry.rb', line 83

def index_status = nil

#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)


137
# File 'lib/ruby_git/status/entry.rb', line 137

def staged? = false

#unmerged?Boolean

Does the entry represent a merge conflict?

  • Merge conflicts are not considered untracked, staged or unstaged

Examples:

entry.conflict? #=> false

Returns:

  • (Boolean)


159
# File 'lib/ruby_git/status/entry.rb', line 159

def unmerged? = false

#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)


126
# File 'lib/ruby_git/status/entry.rb', line 126

def unstaged? = false

#untracked?Boolean

Is the entry an untracked file?

  • Ignored entries are not considered untracked

Examples:

entry.ignored? #=> false

Returns:

  • (Boolean)


114
# File 'lib/ruby_git/status/entry.rb', line 114

def untracked? = false

#worktree_statusSymbol?

Get the worktree status

Examples:

entry.worktree_status #=> :unmodified

Returns:

  • (Symbol, nil)

    worktree status symbol or nil if not applicable



92
# File 'lib/ruby_git/status/entry.rb', line 92

def worktree_status = nil