Class: Space::Models::Repo::Git

Inherits:
Object
  • Object
show all
Includes:
Events, Shell
Defined in:
lib/space/models/repo/git.rb

Instance Attribute Summary collapse

Attributes included from Events

#buffer

Attributes included from Shell

#path

Instance Method Summary collapse

Methods included from Events

#buffering, #buffering?, #notify, #observers, #subscribe

Methods included from Shell

all, #commands, included, refresh, #refresh, #result

Methods included from Shell::Watcher

suspend, suspended?

Constructor Details

#initialize(repo) ⇒ Git

Returns a new instance of Git.



17
18
19
20
# File 'lib/space/models/repo/git.rb', line 17

def initialize(repo)
  @repo = repo
  super(repo.path)
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



15
16
17
# File 'lib/space/models/repo/git.rb', line 15

def repo
  @repo
end

Instance Method Details

#aheadObject



38
39
40
# File 'lib/space/models/repo/git.rb', line 38

def ahead
  result(:status) =~ /Your branch is ahead of .* by (\d+) commits?\./ ? $1.to_i : 0
end

#ahead?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/space/models/repo/git.rb', line 34

def ahead?
  ahead > 0
end

#branchObject



22
23
24
# File 'lib/space/models/repo/git.rb', line 22

def branch
  result(:branch) =~ /^\* (.+)/ && $1.strip
end

#clean?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/space/models/repo/git.rb', line 46

def clean?
  result(:status).include?('nothing to commit (working directory clean)')
end

#commitObject



26
27
28
# File 'lib/space/models/repo/git.rb', line 26

def commit
  result(:commit) =~ /^commit (\S{7})/ && $1
end

#dirty?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/space/models/repo/git.rb', line 42

def dirty?
  !clean?
end

#statusObject



30
31
32
# File 'lib/space/models/repo/git.rb', line 30

def status
  dirty? ? :dirty : (ahead? ? :ahead : :clean)
end