Sha256: 9b9c4fd0f25ce4ca701a626258030a9870c847bc7c2dbd2a7f4b1cb0df0c3f6c

Contents?: true

Size: 1.39 KB

Versions: 12

Compression:

Stored size: 1.39 KB

Contents

require 'rgitflow/tasks/task'

module RGitFlow
  module Tasks
    module SCM
      class Status < RGitFlow::Tasks::Task
        def initialize(git)
          super(git, 'status', 'Check the status of the repository', ['rgitflow', 'scm'])
        end

        protected

        def run
          if dirty?
            error 'There are uncommitted changes in the repository!'

            print_status

            abort
          else
            status 'There are no uncommitted changes in the repository.'
          end
        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'
          added.each { |f| debug "  #{ANSI::Constants::GREEN}#{ANSI::Constants::BRIGHT}#{f.path}#{ANSI::Constants::CLEAR}" }

          debug 'modified'
          modified.each { |f| debug "  #{ANSI::Constants::YELLOW}#{ANSI::Constants::BRIGHT}#{f.path}#{ANSI::Constants::CLEAR}" }

          debug 'deleted'
          deleted.each { |f| debug "  #{ANSI::Constants::RED}#{ANSI::Constants::BRIGHT}#{f.path}#{ANSI::Constants::CLEAR}" }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rgitflow-0.2.0.pre.alpha.pre.21 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0.pre.alpha.pre.20 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.18 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.17 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.16 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.15 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.14 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.13 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.12 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.11 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.1.0.pre.alpha.pre.10 lib/rgitflow/tasks/scm/status.rb