Class: Gitan::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/gitan/repo.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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_statusObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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