Sha256: 5777d99432363318fd740a51b1d50cc395c550b500158781401c28beedcc286c

Contents?: true

Size: 983 Bytes

Versions: 3

Compression:

Stored size: 983 Bytes

Contents

module Space
  module Model
    class Repo
      class Git
        include Source

        commands  status: 'git status',
                  branch: 'git branch --no-color',
                  commit: 'git log -1 --no-color HEAD'

        watch '.'

        attr_reader :repo

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

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

        def dirty?
          !clean?
        end

        def ahead?
          ahead > 0
        end

        def clean?
          result(:status) =~ /nothing to commit (working directory clean)/
        end

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
space-0.0.8 lib/space/model/repo/git.rb
space-0.0.7 lib/space/model/repo/git.rb
space-0.0.6 lib/space/model/repo/git.rb