class Gitan::Repo
Attributes
path[R]
Public Class Methods
new(path, remote_head = false)
click to toggle source
# File lib/gitan/repo.rb, line 16 def initialize(path, remote_head = false) @path = path @remote_head = remote_head end
show_abbreviation(io = $stdout)
click to toggle source
# 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
Public Instance Methods
head()
click to toggle source
# File lib/gitan/repo.rb, line 82 def head command_output_lines("git rev-parse HEAD")[0] end
multiple_branch?()
click to toggle source
# File lib/gitan/repo.rb, line 47 def multiple_branch? lines = command_output_lines("git branch") return lines.size > 1 end
short_status()
click to toggle source
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
# 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?()
click to toggle source
Return true if working tree has changes on stage index.
# 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?()
click to toggle source
Return true if the working tree has un-pulled changes on remote.
# 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?()
click to toggle source
Return true if working tree has change which is commited but not pushed.
# 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?()
click to toggle source
Return true if working tree has untracked changes.
# 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
Private Instance Methods
command_output_lines(str)
click to toggle source
# File lib/gitan/repo.rb, line 94 def command_output_lines(str) Dir.chdir @path `#{str}`.split("\n") end