Sha256: 6f729b1d8e9a9acf577f33832ca1766fad79cda21e38511665bceca11455bf6e

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'open3'

module ThorSCMVersion
  class GitVersion < ScmVersion
    class << self          
      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| new(*tag.split('.')) }.sort.reverse
        end
      end

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

    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
              else
                :patch
              end
      bump!(guess)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thor-scmversion-0.3.1 lib/thor-scmversion/git_version.rb
thor-scmversion-0.2.4 lib/thor-scmversion/git_version.rb
thor-scmversion-0.2.3 lib/thor-scmversion/git_version.rb
thor-scmversion-0.2.2 lib/thor-scmversion/git_version.rb