Class: Git::Status
Overview
The status class gets the status of a git repository
This identifies which files have been modified, added, or deleted from the worktree. Untracked files are also identified.
The Status object is an Enumerable that contains StatusFile objects.
Defined Under Namespace
Classes: StatusFile
Instance Method Summary collapse
-
#[](file)
enumerable method.
-
#added ⇒ Enumerable
Returns an Enumerable containing files that have been added.
-
#added?(file) ⇒ Boolean
Determines whether the given file has been added to the repository.
-
#changed ⇒ Enumerable
Returns an Enumerable containing files that have changed from the git base directory.
-
#changed?(file) ⇒ Boolean
Determines whether the given file has been changed.
-
#deleted ⇒ Enumerable
Returns an Enumerable containing files that have been deleted.
-
#deleted?(file) ⇒ Boolean
Determines whether the given file has been deleted from the repository File path starts at git base directory.
- #each(&block)
-
#initialize(base) ⇒ Status
constructor
A new instance of Status.
- #pretty
- #pretty_file(file)
-
#untracked ⇒ Enumerable
Returns an Enumerable containing files that are not tracked in git.
-
#untracked?(file) ⇒ Boolean
Determines whether the given file has is tracked by git.
Constructor Details
#initialize(base) ⇒ Status
Returns a new instance of Status.
14 15 16 17 |
# File 'lib/git/status.rb', line 14 def initialize(base) @base = base construct_status end |
Instance Method Details
#[](file)
enumerable method
124 125 126 |
# File 'lib/git/status.rb', line 124 def [](file) @files[file] end |
#added ⇒ Enumerable
Returns an Enumerable containing files that have been added. File path starts at git base directory
44 45 46 |
# File 'lib/git/status.rb', line 44 def added @_added ||= @files.select { |_k, f| f.type == 'A' } end |
#added?(file) ⇒ Boolean
Determines whether the given file has been added to the repository
File path starts at git base directory
56 57 58 |
# File 'lib/git/status.rb', line 56 def added?(file) case_aware_include?(:added, :lc_added, file) end |
#changed ⇒ Enumerable
Returns an Enumerable containing files that have changed from the git base directory
24 25 26 |
# File 'lib/git/status.rb', line 24 def changed @_changed ||= @files.select { |_k, f| f.type == 'M' } end |
#changed?(file) ⇒ Boolean
Determines whether the given file has been changed. File path starts at git base directory
36 37 38 |
# File 'lib/git/status.rb', line 36 def changed?(file) case_aware_include?(:changed, :lc_changed, file) end |
#deleted ⇒ Enumerable
Returns an Enumerable containing files that have been deleted. File path starts at git base directory
65 66 67 |
# File 'lib/git/status.rb', line 65 def deleted @_deleted ||= @files.select { |_k, f| f.type == 'D' } end |
#deleted?(file) ⇒ Boolean
Determines whether the given file has been deleted from the repository File path starts at git base directory
77 78 79 |
# File 'lib/git/status.rb', line 77 def deleted?(file) case_aware_include?(:deleted, :lc_deleted, file) end |
#each(&block)
128 129 130 |
# File 'lib/git/status.rb', line 128 def each(&block) @files.values.each(&block) end |
#pretty
102 103 104 105 106 107 108 109 |
# File 'lib/git/status.rb', line 102 def pretty out = '' each do |file| out << pretty_file(file) end out << "\n" out end |
#pretty_file(file)
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/git/status.rb', line 111 def pretty_file(file) <<~FILE #{file.path} \tsha(r) #{file.sha_repo} #{file.mode_repo} \tsha(i) #{file.sha_index} #{file.mode_index} \ttype #{file.type} \tstage #{file.stage} \tuntrac #{file.untracked} FILE end |
#untracked ⇒ Enumerable
Returns an Enumerable containing files that are not tracked in git. File path starts at git base directory
86 87 88 |
# File 'lib/git/status.rb', line 86 def untracked @_untracked ||= @files.select { |_k, f| f.untracked } end |
#untracked?(file) ⇒ Boolean
Determines whether the given file has is tracked by git. File path starts at git base directory
98 99 100 |
# File 'lib/git/status.rb', line 98 def untracked?(file) case_aware_include?(:untracked, :lc_untracked, file) end |