Class: Mixlib::Versioning::Format::GitDescribe

Inherits:
Mixlib::Versioning::Format show all
Defined in:
lib/mixlib/versioning/format/git_describe.rb

Overview

Handles version strings based on git describe output.

SUPPORTED FORMATS


“`text MAJOR.MINOR.PATCH-COMMITS_SINCE-gGIT_SHA1 MAJOR.MINOR.PATCH.PRERELEASE-COMMITS_SINCE-gGIT_SHA1 MAJOR.MINOR.PATCH-PRERELEASE-COMMITS_SINCE-gGIT_SHA1-ITERATION “`

EXAMPLES


“`text 10.16.2-49-g21353f0-1 10.16.2.rc.1-49-g21353f0-1 11.0.0-alpha-10-g642ffed 11.0.0-alpha.1-1-gcea071e “`

Author:

Constant Summary collapse

GIT_DESCRIBE_REGEX =
/^(\d+)\.(\d+)\.(\d+)(?:\-|\.)?(.+)?\-(\d+)\-g([a-f0-9]{7,40})(?:\-)?(\d+)?$/

Instance Attribute Summary collapse

Attributes inherited from Mixlib::Versioning::Format

#build, #input, #iteration, #major, #minor, #patch, #prerelease

Instance Method Summary collapse

Methods inherited from Mixlib::Versioning::Format

#<=>, #build?, #eql?, for, #hash, #in_same_prerelease_line?, #in_same_release_line?, #initialize, #inspect, #prerelease?, #prerelease_build?, #release?, #release_build?, #to_rubygems_string, #to_s, #to_semver_string

Constructor Details

This class inherits a constructor from Mixlib::Versioning::Format

Instance Attribute Details

#commit_shaObject (readonly)

Returns the value of attribute commit_sha


49
50
51
# File 'lib/mixlib/versioning/format/git_describe.rb', line 49

def commit_sha
  @commit_sha
end

#commits_sinceObject (readonly)

Returns the value of attribute commits_since


49
50
51
# File 'lib/mixlib/versioning/format/git_describe.rb', line 49

def commits_since
  @commits_since
end

Instance Method Details

#parse(version_string) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/mixlib/versioning/format/git_describe.rb', line 52

def parse(version_string)
  match = version_string.match(GIT_DESCRIBE_REGEX) rescue nil

  unless match
    raise Mixlib::Versioning::ParseError, "'#{version_string}' is not a valid #{self.class} version string!"
  end

  @major, @minor, @patch, @prerelease, @commits_since, @commit_sha, @iteration = match[1..7]
  @major, @minor, @patch, @commits_since, @iteration = [@major, @minor, @patch, @commits_since, @iteration].map(&:to_i)

  # Our comparison logic is built around SemVer semantics, so
  # we'll store our internal information in that format
  @build = "#{@commits_since}.g#{@commit_sha}.#{@iteration}"
end