Class: RepoManager::Status
- Inherits:
-
Object
- Object
- RepoManager::Status
- Includes:
- Enumerable
- Defined in:
- lib/repo_manager/git/status.rb
Overview
Simplified version of ruby-git’s class that uses Git’s ‘status –porcelain’ command
The –porcelain switch is useful since it handles ignored files and ignores non-commitable changes. Speed is not a big concern. There is only one call needed to the Git binary. No plumbing commands are used.
Defined Under Namespace
Classes: StatusFile
Constant Summary collapse
- CLEAN =
repo status unchanged/clean
0- NOPATH =
bitfields for status
1- INVALID =
2- CHANGED =
4- ADDED =
8- DELETED =
16- UNTRACKED =
32- UNMERGED =
64
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
- #[](file) ⇒ Object
- #added ⇒ Object
-
#added? ⇒ Boolean
False unless a file has been added.
-
#bitfield ⇒ Numeric
0 if CLEAN or bitfield with status: CHANGED | UNTRACKED | ADDED | DELETED | UNMERGED.
- #changed ⇒ Object
-
#changed? ⇒ Boolean
False unless a file has been modified/changed.
- #deleted ⇒ Object
-
#deleted? ⇒ Boolean
False unless a file has been deleted.
- #each ⇒ Object
-
#initialize(scm) ⇒ Status
constructor
A new instance of Status.
- #unmerged ⇒ Object
-
#unmerged? ⇒ Boolean
False unless there is an unmerged file.
- #untracked ⇒ Object
-
#untracked? ⇒ Boolean
False unless there is a new/untracked file.
Constructor Details
#initialize(scm) ⇒ Status
Returns a new instance of Status.
25 26 27 28 29 |
# File 'lib/repo_manager/git/status.rb', line 25 def initialize(scm) @files = {} @scm = scm construct_status end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
23 24 25 |
# File 'lib/repo_manager/git/status.rb', line 23 def files @files end |
Instance Method Details
#[](file) ⇒ Object
86 87 88 |
# File 'lib/repo_manager/git/status.rb', line 86 def [](file) @files[file] end |
#added ⇒ Object
45 46 47 |
# File 'lib/repo_manager/git/status.rb', line 45 def added @files.select { |k, f| f.type == 'A' } end |
#added? ⇒ Boolean
Returns false unless a file has been added.
67 68 69 |
# File 'lib/repo_manager/git/status.rb', line 67 def added? !added.empty? end |
#bitfield ⇒ Numeric
Returns 0 if CLEAN or bitfield with status: CHANGED | UNTRACKED | ADDED | DELETED | UNMERGED.
32 33 34 35 36 37 38 39 |
# File 'lib/repo_manager/git/status.rb', line 32 def bitfield # M ? A D U (changed? ? CHANGED : 0) | (untracked? ? UNTRACKED : 0) | (added? ? ADDED : 0) | (deleted? ? DELETED : 0) | (unmerged? ? UNMERGED : 0) end |
#changed ⇒ Object
41 42 43 |
# File 'lib/repo_manager/git/status.rb', line 41 def changed @files.select { |k, f| f.type == 'M' } end |
#changed? ⇒ Boolean
Returns false unless a file has been modified/changed.
62 63 64 |
# File 'lib/repo_manager/git/status.rb', line 62 def changed? !changed.empty? end |
#deleted ⇒ Object
49 50 51 |
# File 'lib/repo_manager/git/status.rb', line 49 def deleted @files.select { |k, f| f.type == 'D' } end |
#deleted? ⇒ Boolean
Returns false unless a file has been deleted.
72 73 74 |
# File 'lib/repo_manager/git/status.rb', line 72 def deleted? !deleted.empty? end |
#each ⇒ Object
90 91 92 93 94 |
# File 'lib/repo_manager/git/status.rb', line 90 def each @files.each do |k, file| yield file end end |
#unmerged ⇒ Object
57 58 59 |
# File 'lib/repo_manager/git/status.rb', line 57 def unmerged @files.select { |k, f| f.type == 'U' } end |
#unmerged? ⇒ Boolean
Returns false unless there is an unmerged file.
82 83 84 |
# File 'lib/repo_manager/git/status.rb', line 82 def unmerged? !unmerged.empty? end |
#untracked ⇒ Object
53 54 55 |
# File 'lib/repo_manager/git/status.rb', line 53 def untracked @files.select { |k, f| f.type == '?' } end |
#untracked? ⇒ Boolean
Returns false unless there is a new/untracked file.
77 78 79 |
# File 'lib/repo_manager/git/status.rb', line 77 def untracked? !untracked.empty? end |