Sha256: 06d07c37d6bd28aedc8315ef4d5c26e44be0d70e5269871ad9add4bed347d2f9

Contents?: true

Size: 1.88 KB

Versions: 8

Compression:

Stored size: 1.88 KB

Contents

module Lolcommits
  class MercurialInfo < VCSInfo
    attr_accessor :sha, :message, :repo_internal_path, :repo, :url,
                  :author_name, :author_email, :branch

    def self.repo_root?(path = '.')
      File.directory?(File.join(path, '.hg'))
    end

    def self.local_name(path = '.')
      File.basename(File.dirname(Mercurial::Repository.open(path).dothg_path))
    end

    def initialize
      # mercurial sets HG_RESULT for post- hooks
      if ENV.key?('HG_RESULT') && ENV['HG_RESULT'] != '0'
        debug 'Aborting lolcommits hook from failed operation'
        exit 1
      end

      Mercurial.configure do |conf|
        conf.hg_binary_path = 'hg'
      end
      debug 'MercurialInfo: parsed the following values from commit:'
      debug "MercurialInfo: \t#{message}"
      debug "MercurialInfo: \t#{sha}"
      debug "MercurialInfo: \t#{repo_internal_path}"
      debug "MercurialInfo: \t#{repo}"
      debug "MercurialInfo: \t#{branch}"
      debug "MercurialInfo: \t#{author_name}" if author_name
      debug "MercurialInfo: \t#{author_email}" if author_email
    end

    def branch
      @branch ||= last_commit.branch_name
    end

    def message
      @message ||= begin
        message = last_commit.message || ''
        message.split("\n").first
      end
    end

    def sha
      @sha ||= last_commit.id[0..10]
    end

    def repo_internal_path
      @repo_internal_path ||= repository.dothg_path
    end

    def url
      @url ||= repository.path
    end

    def repo
      @repo ||= File.basename(File.dirname(repo_internal_path))
    end

    def author_name
      @author_name ||= last_commit.author
    end

    def author_email
      @author_email ||= last_commit.author_email
    end

    private

    def repository(path = '.')
      @repository ||= Mercurial::Repository.open(path)
    end

    def last_commit
      @commit ||= repository.commits.parent
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lolcommits-0.9.5 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.5.pre1 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.4 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.4.pre1 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.3 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.3.pre3 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.3.pre2 lib/lolcommits/backends/mercurial_info.rb
lolcommits-0.9.3.pre1 lib/lolcommits/backends/mercurial_info.rb