Class: Git::Status
Overview
A class for git status
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 File path starts at git base directory.
-
#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.
8 9 10 11 |
# File 'lib/git/status.rb', line 8 def initialize(base) @base = base construct_status end |
Instance Method Details
#[](file)
enumerable method
119 120 121 |
# File 'lib/git/status.rb', line 119 def [](file) @files[file] end |
#added ⇒ Enumerable
Returns an Enumerable containing files that have been added. File path starts at git base directory
39 40 41 |
# File 'lib/git/status.rb', line 39 def 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
51 52 53 |
# File 'lib/git/status.rb', line 51 def added?(file) added.member?(file) end |
#changed ⇒ Enumerable
Returns an Enumerable containing files that have changed from the git base directory
18 19 20 |
# File 'lib/git/status.rb', line 18 def 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
30 31 32 |
# File 'lib/git/status.rb', line 30 def changed?(file) changed.member?(file) end |
#deleted ⇒ Enumerable
Returns an Enumerable containing files that have been deleted. File path starts at git base directory
60 61 62 |
# File 'lib/git/status.rb', line 60 def 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
72 73 74 |
# File 'lib/git/status.rb', line 72 def deleted?(file) deleted.member?(file) end |
#each(&block)
123 124 125 |
# File 'lib/git/status.rb', line 123 def each(&block) @files.values.each(&block) end |
#pretty
97 98 99 100 101 102 103 104 |
# File 'lib/git/status.rb', line 97 def pretty out = '' each do |file| out << pretty_file(file) end out << "\n" out end |
#pretty_file(file)
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/git/status.rb', line 106 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
81 82 83 |
# File 'lib/git/status.rb', line 81 def 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
93 94 95 |
# File 'lib/git/status.rb', line 93 def untracked?(file) untracked.member?(file) end |