Sha256: a970185d6dc5ce3f6e09608bbfac16ba049d869b590034b1074f666e0e0c6f01

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

require 'rgitflow/tasks/task'

module RGitFlow
  module Tasks
    class 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.diff.size > 0
        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

8 entries across 8 versions & 1 rubygems

Version Path
rgitflow-0.2.1.pre.alpha.pre.32 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.1.pre.alpha.pre.28 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0.pre.alpha.pre.27 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0.pre.alpha.pre.26 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0.pre.alpha.pre.25 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0.pre.alpha.pre.23 lib/rgitflow/tasks/scm/status.rb
rgitflow-0.2.0.pre.alpha.pre.22 lib/rgitflow/tasks/scm/status.rb