Class Sprout::GitTask
In: sprout/lib/sprout/tasks/git_task.rb
Parent: Rake::Task

A Rake task for continous integration and automated deployment. This task will automatically load a version_file, increment the last digit (revision), create a new tag in Git with the full version number, and push tags to the remote Git repository.

To use this task, simply add the following to your rakefile:

  desc 'Increment revision, tag and push with git'
  git :tag do |t|
    t.version_file = 'version.txt'
  end

Methods

define   define_task   execute   new   scm   scm=   version  

Attributes

branch  [RW]  The local branch to send, defaults to ‘master’.
commit_message  [RW]  Message to use when committing after incrementing revision number. Defaults to ‘Incremented revision number’.
remote  [RW]  The remote branch to use, defaults to ‘origin’.
version_file  [RW]  Path to a plain text file that contains a three-part version number. @see VersionFile

Public Class methods

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 59
    def self.define_task(args, &block)
      begin
        require 'git'
      rescue LoadError => e
        puts "You need to install the 'git' gem. Try running: sudo gem install git"
        raise e
      end
      t = super
      yield t if block_given?
      t.define
      return t
    end

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 32
    def initialize(name, app)
      super
      @remote = 'origin'
      @branch = 'master'
      @commit_message = 'Incremented revision number'
    end

Public Instance methods

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 43
    def define
      validate
      @version = VersionFile.new(version_file)
    end

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 48
    def execute(*args)
      super
      # Fix numeric comparison....
      while(get_tags.index(@version.to_tag)) do
        @version.increment_revision
      end
      create_tag(@version.to_tag)
      commit
      push
    end

Will open on path if no SCM exists yet.

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 78
    def scm
      if(@scm.nil?)
        path = path_to_git
        raise GitTaskError.new("We don't appear to be inside of a git repository") if path.nil?
        @scm = Git.open(path)
      end

      @scm
    end

Accessor for mocking the git gem.

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 73
    def scm=(scm)
      @scm = scm
    end

[Source]

# File sprout/lib/sprout/tasks/git_task.rb, line 39
    def version
      @version.to_s
    end

[Validate]