Sha256: b36b8bfcc4ff3b230e647f2fa5d7ea3b68ac386e4bc84d5e0f8bb4aea5e6a903

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

module Stove
  class Plugin::Git < Plugin::Base
    id 'git'
    description 'Tag and push to a git remote'

    validate(:repository) do
      File.directory?(File.join(Dir.pwd, '.git'))
    end

    validate(:clean) do
      git_null('status -s').strip.empty?
    end

    validate(:up_to_date) do
      git_null('fetch')
      local_sha  = git_null("rev-parse #{branch}").strip
      remote_sha = git_null("rev-parse #{remote}/#{branch}").strip

      log.debug("Local SHA: #{local_sha}")
      log.debug("Remote SHA: #{remote_sha}")

      local_sha == remote_sha
    end

    run('Tagging new release') do
      annotation_type = options[:sign] ? '-s' : '-a'
      tag = cookbook.tag_version

      git %|tag #{annotation_type} #{tag} -m "Release #{tag}"|
      git %|push #{remote} #{branch}|
      git %|push #{remote} #{tag}|
    end

    private

    def git(command, errors = true)
      log.debug("Running `git #{command}', errors: #{errors}")
      Dir.chdir(cookbook.path) do
        response = %x|git #{command}|

        if errors && !$?.success?
          raise Error::GitFailed.new(command: command)
        end

        response
      end
    end

    def git_null(command)
      null = case RbConfig::CONFIG['host_os']
             when /mswin|mingw|cygwin/
               'NUL'
             else
               '/dev/null'
             end

      git("#{command} 2>#{null}", false)
    end

    def remote
      options[:remote]
    end

    def branch
      options[:branch]
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
stove-4.1.1 lib/stove/plugins/git.rb
stove-4.1.0 lib/stove/plugins/git.rb
stove-4.0.0 lib/stove/plugins/git.rb
stove-3.2.8 lib/stove/plugins/git.rb
wood-stove-3.2.9000 lib/stove/plugins/git.rb
stove-3.2.7 lib/stove/plugins/git.rb
stove-3.2.6 lib/stove/plugins/git.rb
stove-3.2.5 lib/stove/plugins/git.rb
stove-3.2.4 lib/stove/plugins/git.rb
stove-3.2.3 lib/stove/plugins/git.rb
stove-3.2.2 lib/stove/plugins/git.rb
stove-3.2.1 lib/stove/plugins/git.rb
stove-3.0.0 lib/stove/plugins/git.rb