Class: ThorSCMVersion::GitVersion

Inherits:
ScmVersion show all
Defined in:
lib/thor-scmversion/git_version.rb

Constant Summary

Constants inherited from ScmVersion

ScmVersion::VERSION_FILENAME, ScmVersion::VERSION_FORMAT

Instance Attribute Summary

Attributes inherited from ScmVersion

#build, #major, #minor, #patch, #prerelease

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ScmVersion

#<=>, #bump!, from_path, from_tag, #initialize, #reset_for, #to_s, #write_version

Constructor Details

This class inherits a constructor from ThorSCMVersion::ScmVersion

Class Method Details

.all_from_path(path) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/thor-scmversion/git_version.rb', line 6

def all_from_path(path)
  Dir.chdir(path) do
    tags = Open3.popen3("git tag") { |stdin, stdout, stderr| stdout.read }.split(/\n/)
    version_tags = tags.select { |tag| tag.match(ScmVersion::VERSION_FORMAT) }
    version_tags.collect { |tag| from_tag(tag) }.sort.reverse
  end
end

.retrieve_tagsObject



14
15
16
# File 'lib/thor-scmversion/git_version.rb', line 14

def retrieve_tags
  ShellUtils.sh("git fetch --all")
end

Instance Method Details

#auto_bumpObject

Check the commit messages to see what type of bump is required



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/thor-scmversion/git_version.rb', line 25

def auto_bump
  last_tag = self.class.from_path.to_s
  logs = ShellUtils.sh "git log --abbrev-commit --format=oneline #{last_tag}.."
  guess = if logs =~ /\[major\]|\#major/i
            :major
          elsif logs =~ /\[minor\]|\#minor/i
            :minor
          elsif logs =~ /\[prerelease\s?(#{Prerelease::TYPE_FORMAT})?\]|\#prerelease\-?(#{Prerelease::TYPE_FORMAT})?/
            prerelease_type = $1 || $2
            :prerelease
          elsif logs =~ /\[patch\]|\#patch/i
            :patch
          else
            :build
          end
  bump!(guess, prerelease_type)
end

#tagObject



19
20
21
22
# File 'lib/thor-scmversion/git_version.rb', line 19

def tag
  ShellUtils.sh "git tag -a -m \"Version #{self}\" #{self}"
  ShellUtils.sh "git push --tags || true"
end