Sha256: ef942f978f3aff5f7a4f747ddf575a30b5ad9bca6d53315c76454d71f43727f7

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

require 'rgitflow/tasks/task'

module RGitFlow
  module Tasks
    class SCM
      class Tag < RGitFlow::Tasks::Task
        def initialize(git)
          super(git, 'tag', 'Tags the repository',
                ['rgitflow', 'scm'])
        end

        protected

        def run
          status 'Creating tag...'
          if dirty?
            error 'There are uncommitted changes in the repository!'

            print_status

            abort
          else
            status 'There are no uncommitted changes in the repository.'
          end
          tag = ENV['TAG'] || ("#{RGitFlow::Config.options[:tag]}" %
              RGitFlow::VERSION.to_s)
          unless @git.tags.select { |t| t.name == tag }.length == 0
            error 'Cannot create a tag that already exists!'
            abort
          end
          @git.add_tag tag, { :m => "tagging as #{tag}" }

          @git.push 'origin', @git.current_branch, { :tags => true }

          status 'Successfully created tag!'
        end

        def dirty?
          @git.dirty?
        end

        def print_status
          added    = []
          modified = []
          deleted  = []

          @git.diff.each { |f|
            if f.type == 'new'
              added << f
            elsif f.type == 'modified'
              modified << f
            elsif f.type == 'deleted'
              deleted << f
            end
          }

          debug 'added'
          msg = %Q(#{ANSI::Constants::GREEN}#{ANSI::Constants::BRIGHT}
          #{f.path}#{ANSI::Constants::CLEAR})
          added.each { |f| debug "  #{msg}" }

          debug 'modified'
          msg = %Q(#{ANSI::Constants::YELLOW}#{ANSI::Constants::BRIGHT}
          #{f.path}#{ANSI::Constants::CLEAR})
          modified.each { |f| debug "  #{msg}" }

          debug 'deleted'
          msg = %Q(#{ANSI::Constants::RED}#{ANSI::Constants::BRIGHT}
          #{f.path}#{ANSI::Constants::CLEAR})
          deleted.each { |f| debug "  #{msg}" }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rgitflow-0.2.0.pre.alpha.pre.26 lib/rgitflow/tasks/scm/tag.rb
rgitflow-0.2.0.pre.alpha.pre.23 lib/rgitflow/tasks/scm/tag.rb
rgitflow-0.2.0.pre.alpha.pre.22 lib/rgitflow/tasks/scm/tag.rb