Sha256: 2c1556031e0520ed44364364394b2477fde096d712a5aa3b8a0653be00f49772

Contents?: true

Size: 1.01 KB

Versions: 38

Compression:

Stored size: 1.01 KB

Contents

require 'engineyard/error'
require 'escape'
require 'pathname'

module EY
  class Repo

    attr_reader :path

    def initialize(repo_path='.')
      self.path = repo_path
    end

    def path=(new_path)
      @path = Pathname.new(new_path).expand_path
    end

    def exist?
      dotgit.directory?
    end

    def current_branch
      if exist? && (head = dotgit("HEAD").read.chomp) && head.gsub!("ref: refs/heads/", "")
        head
      else
        nil
      end
    end

    def urls
      @urls ||= config('remote.*.url').map { |c| c.split.last }
    end

    def has_remote?(repository_uri)
      urls.include?(repository_uri)
    end

    def fail_on_no_remotes!
      if urls.empty?
        raise NoRemotesError.new(path)
      end
    end

    private

    def dotgit(child='')
      path.join('.git', child)
    end

    def config(pattern)
      config_file = Escape.shell_command([dotgit('config').to_s])
      `git config -f #{config_file} --get-regexp '#{pattern}'`.split(/\n/)
    end

  end # Repo
end # EY

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
engineyard-1.4.29 lib/engineyard/repo.rb
engineyard-1.4.28 lib/engineyard/repo.rb
engineyard-1.4.27 lib/engineyard/repo.rb
engineyard-1.4.24 lib/engineyard/repo.rb
engineyard-1.4.23 lib/engineyard/repo.rb
engineyard-1.4.22 lib/engineyard/repo.rb
engineyard-1.4.21 lib/engineyard/repo.rb
engineyard-1.4.20 lib/engineyard/repo.rb
engineyard-1.4.19 lib/engineyard/repo.rb
engineyard-1.4.18 lib/engineyard/repo.rb
engineyard-1.4.17 lib/engineyard/repo.rb
engineyard-1.4.16 lib/engineyard/repo.rb
engineyard-1.4.15 lib/engineyard/repo.rb
engineyard-1.4.14 lib/engineyard/repo.rb
engineyard-1.4.13 lib/engineyard/repo.rb
engineyard-1.4.11 lib/engineyard/repo.rb
engineyard-1.4.10 lib/engineyard/repo.rb
engineyard-1.4.9 lib/engineyard/repo.rb
engineyard-1.4.8 lib/engineyard/repo.rb
engineyard-1.4.7 lib/engineyard/repo.rb