Class: Gitan::Repo
- Inherits:
-
Object
- Object
- Gitan::Repo
- Defined in:
- lib/gitan/repo.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Repo
constructor
A new instance of Repo.
- #multiple_branch? ⇒ Boolean
-
#short_status ⇒ Object
Return short status as String.
-
#to_be_commited? ⇒ Boolean
Return true if working tree has changes on stage index.
-
#to_be_pushed? ⇒ Boolean
Return true if working tree has change which is commited but not pushed.
-
#to_be_staged? ⇒ Boolean
Return true if working tree has untracked changes.
Constructor Details
#initialize(path) ⇒ Repo
Returns a new instance of Repo.
8 9 10 |
# File 'lib/gitan/repo.rb', line 8 def initialize(path) @path = path end |
Class Method Details
.show_abbreviation(io = $stdout) ⇒ Object
4 5 6 |
# File 'lib/gitan/repo.rb', line 4 def self.show_abbreviation(io = $stdout) io.puts "==== B: multiple branches, S: to be staged, C: to be commited, P: to be pushed." end |
Instance Method Details
#multiple_branch? ⇒ Boolean
35 36 37 38 |
# File 'lib/gitan/repo.rb', line 35 def multiple_branch? lines = command_output_lines("git branch") return lines.size > 1 end |
#short_status ⇒ Object
Return short status as String. E.g, “BSCP path”, “ C path” B: contain multiple Branches S: to be staged C: to be commited P: to be pushed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gitan/repo.rb', line 19 def short_status b = " " b = "B" if multiple_branch? s = " " s = "S" if to_be_staged? c = " " c = "C" if to_be_commited? p = " " p = "P" if to_be_pushed? return (b + s + c + p + " " + @path) end |
#to_be_commited? ⇒ Boolean
Return true if working tree has changes on stage index.
47 48 49 50 |
# File 'lib/gitan/repo.rb', line 47 def to_be_commited? lines = command_output_lines("git status -s") return lines.select {|line| line =~ /^[^\?]/} != [] end |
#to_be_pushed? ⇒ Boolean
Return true if working tree has change which is commited but not pushed.
53 54 55 56 57 |
# File 'lib/gitan/repo.rb', line 53 def to_be_pushed? head = command_output_lines("git rev-parse HEAD")[0] remote_lines = command_output_lines("git rev-parse --remotes") return (! remote_lines.include?(head)) end |
#to_be_staged? ⇒ Boolean
Return true if working tree has untracked changes.
41 42 43 44 |
# File 'lib/gitan/repo.rb', line 41 def to_be_staged? lines = command_output_lines("git status -s") return lines.select {|line| line =~ /^\?\?/} != [] end |