Class: Gitw::Git::StatusFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gitw/git/status.rb

Overview

encapsulate git status file entry

Constant Summary collapse

STATUS_LINE_RE =
/^(?<index_status>.)
(?<workingtree_status>.)
\s
(?:(?<orig_path>.*?)\s->\s)?
(?<path>.*)$/x.freeze
STATUS_MAP =
{
  ' ' => :unmodified,
  'M' => :modified,
  'T' => :file_type_changed,
  'A' => :added,
  'D' => :deleted,
  'R' => :renamed,
  'C' => :copied,
  'U' => :updated,
  '?' => :untracked,
  '!' => :ignored
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, index_status: nil, workingtree_status: nil, orig_path: nil) ⇒ StatusFile

Returns a new instance of StatusFile.



61
62
63
64
65
66
# File 'lib/gitw/git/status.rb', line 61

def initialize(path, index_status: nil, workingtree_status: nil, orig_path: nil)
  @path = path
  @index_status = index_status
  @workingtree_status = workingtree_status
  @orig_path = orig_path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



59
60
61
# File 'lib/gitw/git/status.rb', line 59

def path
  @path
end

Class Method Details

.parse(status_line) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/gitw/git/status.rb', line 91

def self.parse(status_line)
  return unless (match = STATUS_LINE_RE.match(status_line))

  new(match[:path],
      index_status: match[:index_status],
      workingtree_status: match[:workingtree_status],
      orig_path: match[:orig_path])
end

Instance Method Details

#index_changed?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/gitw/git/status.rb', line 68

def index_changed?
  return false if STATUS_MAP[@index_status] == :unmodified
  return false if STATUS_MAP[@index_status] == :ignored
  return false if STATUS_MAP[@index_status] == :untracked

  true
end

#untracked?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
# File 'lib/gitw/git/status.rb', line 84

def untracked?
  return true if STATUS_MAP[@index_status] == :untracked
  return true if STATUS_MAP[@workingtree_status] == :untracked

  false
end

#workingtree_changed?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'lib/gitw/git/status.rb', line 76

def workingtree_changed?
  return false if STATUS_MAP[@workingtree_status] == :unmodified
  return false if STATUS_MAP[@workingtree_status] == :ignored
  return false if STATUS_MAP[@workingtree_status] == :untracked

  true
end