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.
16 17 18 19 |
# File 'lib/git/status.rb', line 16 def initialize(base) @base = base construct_status end |
Instance Method Details
#[](file)
enumerable method
126 127 128 |
# File 'lib/git/status.rb', line 126 def [](file) @files[file] end |
#added ⇒ Enumerable
Returns an Enumerable containing files that have been added. File path starts at git base directory
46 47 48 |
# File 'lib/git/status.rb', line 46 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
58 59 60 |
# File 'lib/git/status.rb', line 58 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
26 27 28 |
# File 'lib/git/status.rb', line 26 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
38 39 40 |
# File 'lib/git/status.rb', line 38 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
67 68 69 |
# File 'lib/git/status.rb', line 67 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
79 80 81 |
# File 'lib/git/status.rb', line 79 def deleted?(file) case_aware_include?(:deleted, :lc_deleted, file) end |
#each(&block)
130 131 132 |
# File 'lib/git/status.rb', line 130 def each(&block) @files.values.each(&block) end |
#pretty
104 105 106 107 108 109 110 111 |
# File 'lib/git/status.rb', line 104 def pretty out = +'' each do |file| out << pretty_file(file) end out << "\n" out end |
#pretty_file(file)
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/git/status.rb', line 113 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
88 89 90 |
# File 'lib/git/status.rb', line 88 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
100 101 102 |
# File 'lib/git/status.rb', line 100 def untracked?(file) case_aware_include?(:untracked, :lc_untracked, file) end |