class GitRoutines
Attributes
default_branch[RW]
summary[RW]
title[RW]
Public Class Methods
ask_for(question, default = nil)
click to toggle source
# File lib/git-routines.rb, line 56 def ask_for(question, default = nil) print "#{question}#{" [#{default}]" unless default.nil?}: " value = STDIN.readline.strip value == '' ? default : value end
branch()
click to toggle source
# File lib/git-routines.rb, line 42 def branch @branch ||= ask_for('Branch name') @branch.strip.downcase.gsub(/[^\w\d\/]+/, '-') end
config(key, question = nil, scope = nil, default = nil)
click to toggle source
# File lib/git-routines.rb, line 74 def config(key, question = nil, scope = nil, default = nil) value = git(:config, key).strip if value == '' and !question.nil? value = ask_for(question, default) git :config, scope, key, value end value end
current_branch()
click to toggle source
# File lib/git-routines.rb, line 97 def current_branch `git rev-parse --abbrev-ref HEAD`.strip end
finish()
click to toggle source
# File lib/git-routines.rb, line 34 def finish @branch = current_branch run_hook :setup run_hook :before_finish git :checkout, default_branch run_hook :after_finish end
git(command, *options)
click to toggle source
# File lib/git-routines.rb, line 70 def git(command, *options) `git #{command} #{options.map{ |o| o.is_a?(Symbol) ? "--#{o}" : o}.join(' ')}` end
include_plugin(plugin)
click to toggle source
# File lib/git-routines.rb, line 89 def include_plugin(plugin) @included_plugins ||= [] return if @included_plugins.include?(plugin) @included_plugins << plugin file = File.expand_path("../git-routines/plugins/#{plugin}.rb", __FILE__) instance_eval File.read(file) end
requires_gem(name)
click to toggle source
# File lib/git-routines.rb, line 83 def requires_gem(name) require name rescue LoadError abort "\nPlease install the `#{name}` Gem first:\n\ngem install #{name}\n\n" end
select_multiple_of(question, *option_lists)
click to toggle source
# File lib/git-routines.rb, line 62 def select_multiple_of(question, *option_lists) select_of("#{question} (comma separated)", *option_lists) end
select_one_of(question, *option_lists)
click to toggle source
# File lib/git-routines.rb, line 66 def select_one_of(question, *option_lists) select_of(question, *option_lists).first end
start()
click to toggle source
# File lib/git-routines.rb, line 27 def start run_hook :setup run_hook :before_start git :checkout, "-b #{branch}" run_hook :after_start end
Private Class Methods
list_options(*option_lists)
click to toggle source
# File lib/git-routines.rb, line 112 def list_options(*option_lists) option_lists.each do |list| next unless list.any? puts "\n" list.each_with_index do |a, b| key, value = list.is_a?(Hash) ? [a[0], a[1]] : [b + 1, a] puts "[#{key}]".to_s.rjust(@column_size) + " #{value}" end end puts "\n" end
select_of(question, *option_lists)
click to toggle source
# File lib/git-routines.rb, line 103 def select_of(question, *option_lists) list_options *option_lists choice = ask_for(question) abort 'Command aborted.' if choice.nil? choice.split(',').map do |item| item =~ /^\d+$/ ? item.to_i - 1 : item.to_sym end end