class Rookie::Tasks::Git
This task provides a way to quickly and easily release git projects using a gem specification.
Attributes
Logger which will be used to log the git messages. Logs to SDTOUT by default.
The version the project will be released under.
Directory which contains the git repository.
Public Class Methods
Creates a new git task with the given parameters. Yields the instance if given a block.
Tasks
do not get defined automatically; don't forget to call define_tasks!
# File lib/rookie/tasks/git.rb, line 32 def initialize(release_version = nil, working_dir = Dir.pwd, logger = nil) self.logger = logger self.working_directory = working_dir self.release_version = release_version yield self if block_given? end
Public Instance Methods
Returns whether the repository already contains the given tag name.
# File lib/rookie/tasks/git.rb, line 72 def already_tagged?(tag_name) git.tag tag_name rescue ::Git::GitTagNameDoesNotExist false end
Defines the git tasks.
# File lib/rookie/tasks/git.rb, line 79 def define_tasks! namespace :git do desc 'Tags latest commit with the given tag name' task :tag, :tag_name do |task, args| tag! args[:tag_name] end desc 'Pushes changes to a remote repository' task :push, :remote, :branch do |task, args| args.with_defaults remote: 'origin', branch: 'master' push! args[:remote], args[:branch] end namespace :push do desc 'Pushes tags to a remote repository' task :tags, :remote, :branch do |task, args| args.with_defaults remote: 'origin', branch: 'master' push! args[:remote], args[:branch] end end desc 'Release current version' task :release, :version, :remote, :branch do |task, args| args.with_defaults version: release_tag, remote: 'origin', branch: 'master' release! args[:version], args[:remote], args[:branch] end end end
Lazily created logger.
# File lib/rookie/tasks/git.rb, line 23 def logger @logger ||= create_logger end
Pushes the changes in the given branch to the given remote repository.
Tags will be pushed too if tags
is true
.
# File lib/rookie/tasks/git.rb, line 60 def push!(remote = 'origin', branch = 'master', tags = false) git.push remote, branch, tags end
Tags the latest commit with the given version tag and pushes the given branch to the given remote repository, including tags.
# File lib/rookie/tasks/git.rb, line 66 def release!(version_tag = release_tag, remote = 'origin', branch = 'master') tag! version_tag push! remote, branch, true end
Computes a release tag for the given version.
# File lib/rookie/tasks/git.rb, line 40 def release_tag(version = release_version) "v#{version}" end
Tags the latest commit in the repository with the given tag name.
If the tag is invalid or already in the repository, an error will be raised prior to tagging.
# File lib/rookie/tasks/git.rb, line 48 def tag!(tag_name) raise "Tag '#{tag_name}' is invalid" if tag_name.nil? or tag_name.empty? if already_tagged? tag_name raise "Tag '#{tag_name}' already in repository" else git.add_tag tag_name end end
Protected Instance Methods
Creates a logger to STDOUT at INFO level with a custom formatter.
# File lib/rookie/tasks/git.rb, line 116 def create_logger ::Logger.new(STDOUT).tap do |logger| logger.level = ::Logger::INFO logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" } end end
Lazily created git handle. Uses the logger returned by logger
.
# File lib/rookie/tasks/git.rb, line 111 def git @git ||= ::Git.open working_directory, :log => logger end