Module: Builderator::Control::Version::Git

Extended by:
SCM
Defined in:
lib/builderator/control/version/git.rb

Overview

SCM implementation for Git

Constant Summary collapse

COMMIT_FORMAT =
/^(?<hash>[a-f0-9]+)(?:\s+\((?<tags>.+?)\))?\s+(?<message>.+)$/
TAG_FORMAT =
%r{tag: ([a-zA-Z0-9\.\-\+/_]+)}

Class Method Summary collapse

Methods included from SCM

_history, _tags, history, history, provider, providers, register, supported?, tags, tags, unregister

Class Method Details

._historyObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/builderator/control/version/git.rb', line 24

def self._history
  `git log --pretty='format:%H %d %s' HEAD`.chomp
    .split("\n")
    .map { |string| string.match(COMMIT_FORMAT) }
    .reject(&:nil?)
    .map do |commit|
      {
        :id => commit[:hash],
        :message => commit[:message]
      }.tap do |c|
        tag_match = commit[:tags].scan(TAG_FORMAT)
                    .flatten
                    .reject(&:nil?) unless commit[:tags].nil?

        c[:tags] = tag_match unless tag_match.nil? || tag_match.empty?
      end
    end
end

.supported?Boolean

Is there a .git repo in the project root?

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/builderator/control/version/git.rb', line 18

def self.supported?
  return true if ENV['GIT_DIR'] && File.exist?(ENV['GIT_DIR'])

  Util.relative_path('.git').exist?
end