Class: Gitan::Repo
- Inherits:
-
Object
- Object
- Gitan::Repo
- Defined in:
- lib/gitan/repo.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #head ⇒ Object
-
#initialize(path, remote_head = false) ⇒ 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_pulled? ⇒ Boolean
Return true if the working tree has un-pulled changes on remote.
-
#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, remote_head = false) ⇒ Repo
Returns a new instance of Repo.
16 17 18 19 |
# File 'lib/gitan/repo.rb', line 16 def initialize(path, remote_head = false) @path = path @remote_head = remote_head end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/gitan/repo.rb', line 3 def path @path end |
Class Method Details
.show_abbreviation(io = $stdout) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/gitan/repo.rb', line 5 def self.show_abbreviation(io = $stdout) #io.puts "==== B: multiple branches, S: to be staged, C: to be commited, P: to be pushed, L: to be pulled." io.puts "Abbreviations:" io.puts " L: to be pulled." io.puts " B: multiple branches" io.puts " S: to be staged" io.puts " C: to be commited" io.puts " P: to be pushed" io.puts "========================================" end |
Instance Method Details
#head ⇒ Object
82 83 84 |
# File 'lib/gitan/repo.rb', line 82 def head command_output_lines("git rev-parse HEAD")[0] end |
#multiple_branch? ⇒ Boolean
47 48 49 50 |
# File 'lib/gitan/repo.rb', line 47 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gitan/repo.rb', line 28 def short_status l = " " l = "L" if @remote_head && to_be_pulled? 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 (l + b + s + c + p + " " + File.basename(@path)) end |
#to_be_commited? ⇒ Boolean
Return true if working tree has changes on stage index.
64 65 66 67 |
# File 'lib/gitan/repo.rb', line 64 def to_be_commited? lines = command_output_lines("git status --porcelain") return lines.select {|line| line =~ /^[^\?]/} != [] end |
#to_be_pulled? ⇒ Boolean
Return true if the working tree has un-pulled changes on remote.
87 88 89 90 |
# File 'lib/gitan/repo.rb', line 87 def to_be_pulled? lines = command_output_lines('git log --pretty=format:"%H"') return ! lines.include?(@remote_head) end |
#to_be_pushed? ⇒ Boolean
Return true if working tree has change which is commited but not pushed.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gitan/repo.rb', line 70 def to_be_pushed? result = true remote_lines = command_output_lines("git rev-parse --remotes") result = false if remote_lines.include?(head) fetch_head = command_output_lines("git rev-parse FETCH_HEAD")[0] result = false if head == fetch_head return result end |
#to_be_staged? ⇒ Boolean
Return true if working tree has untracked changes.
53 54 55 56 57 58 59 60 61 |
# File 'lib/gitan/repo.rb', line 53 def to_be_staged? lines = command_output_lines("git status --porcelain") result = false lines.each do |line| result = true if line =~ /^\?\? / result = true if line =~ /^ . / end return result end |