Class: Gem::Tasks::SCM::Status

Inherits:
Task
  • Object
show all
Defined in:
lib/rubygems/tasks/scm/status.rb

Overview

The scm:status task.

Constant Summary

Constants included from Printing

Printing::ANSI_BRIGHT, Printing::ANSI_CLEAR, Printing::ANSI_GREEN, Printing::ANSI_RED, Printing::ANSI_YELLOW, Printing::DEBUG_PREFIX, Printing::ERROR_PREFIX, Printing::STATUS_PREFIX

Instance Attribute Summary

Attributes inherited from Task

#project

Instance Method Summary collapse

Methods inherited from Task

#bundle, #gem, #gemspec_tasks, #invoke, #namespaced_tasks, #run, #task?

Methods included from Printing

#debug, #error

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Status

Initializes the status task.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
# File 'lib/rubygems/tasks/scm/status.rb', line 17

def initialize(options={})
  super()

  yield self if block_given?
  define
end

Instance Method Details

#defineObject

Defines the status task.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubygems/tasks/scm/status.rb', line 27

def define
  namespace :scm do
    task :status do
      if dirty?
        error "Project has uncommitted changes!"

        status
        abort
      end
    end
  end

  # alias the `validate` task to scm:status
  task :validate => 'scm:status'
end

#dirty?Boolean

Checks the status of the project repository.

Returns:

  • (Boolean)

    Specifies whether the repository is dirty.

Since:

  • 0.2.1



53
54
55
56
57
58
59
60
61
62
# File 'lib/rubygems/tasks/scm/status.rb', line 53

def dirty?
  status = case @project.scm
           when :git then `git status --porcelain --untracked-files=no`
           when :hg  then `hg status --quiet`
           when :svn then `svn status --quiet`
           else            ''
           end

  return !status.chomp.empty?
end

#statusObject

Displays the status of the project repository.



69
70
71
72
73
74
75
# File 'lib/rubygems/tasks/scm/status.rb', line 69

def status
  case @project.scm
  when :git then run 'git', 'status', '--untracked-files=no'
  when :hg  then run 'hg', 'status', '--quiet'
  when :svn then run 'svn', 'status', '--quiet'
  end
end