Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 186 lines (155 sloc) 3.6 KB
#!/usr/bin/env ruby
require "rubygems"
require "rake"
require "rake/tasklib"
require "colorize"
require "fileutils"
#require 'mysql'
#require 'jdbc-mysql'
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
# An object is present if it's not blank.
def present?
!blank?
end
def presence
self if present?
end
end
class NilClass #:nodoc:
def blank?
true
end
end
class FalseClass #:nodoc:
def blank?
true
end
end
class TrueClass #:nodoc:
def blank?
false
end
end
class Array #:nodoc:
alias_method :blank?, :empty?
end
class Hash #:nodoc:
alias_method :blank?, :empty?
end
class String #:nodoc:
def blank?
self !~ /\S/
end
end
class Numeric #:nodoc:
def blank?
false
end
end
include FileUtils
Rake.application.init("sake")
desc "Push current branch"
task :gfp do
branch_name = @git_help.current_branch
if branch_name == 'master'
abort("Abort!!! No force to master please!!")
end
puts "Force Pushing branch #{branch_name}"
system("git push origin #{branch_name} -u -v --force-with-lease")
end
desc "Push current branch"
task :gp do
branch_name = @git_help.current_branch
puts "Pushing branch #{branch_name}"
system("git push origin #{branch_name} -u -v")
end
desc "Rebase current branch"
task :gb do
branch_name = @git_help.current_branch
puts "Rebasing branch #{branch_name}"
system("git rebase origin/#{branch_name}")
end
desc "Open merge tool with vimdiff"
task :gmt do
system("git mergetool -t vimdiff")
end
desc "Merge remote of current with current branch"
task :gm do
branch_name = @git_help.current_branch
puts "Merging origin/#{branch_name} with #{branch_name}"
system("git merge origin/#{branch_name}")
end
desc "Rebase remote of current with current branch"
task :gb do
branch_name = @git_help.current_branch
puts "Rebasing origin/#{branch_name} with #{branch_name}"
system("git rebase origin/#{branch_name}")
end
desc "Show diff"
task :gd do
system("git diff")
end
desc "Do hard reset"
task :grst do
system("git reset --hard HEAD")
end
desc "Creating a tracking local branch"
task :gct do
branch_name = ENV['branch']
if(branch_name.blank?)
abort("Argument branch=".red+"<branch_name>".green)
else
system("git checkout --track -b #{branch_name} origin/#{branch_name}")
end
end
desc "Globally available task list"
task :default do
Rake.application.tasks.each do |task|
puts sprintf("%-25s : %s", task.name.bold.red, task.name)
end
end
desc "truncate db"
task :dbt do
db = ENV['db']
username = ENV['user'] || 'root'
password = ENV['password'] || ''
host = ENV['host'] || 'localhost'
if not db.blank?
db_util = Sake::Database.new()
db_util.truncate_db(db,username,password,host)
else
abort("Please supply db name to truncate")
end
end
module Sake
class Git
def current_branch
cmd_output = `git symbolic-ref --short HEAD`
cmd_output.strip
end
def head_sha
`git rev-list --max-count=1 HEAD`.strip
end
end
class Database
def truncate_db(db,username = 'root',password = '', host = 'localhost')
puts "Truncating Database : ".bold + db.red.bold
puts "** Press enter to continue **".green.bold
STDIN.getc
connection = Mysql.connect(host,username,password,db)
result = connection.real_query("show tables")
tables = []
result.each_hash { |table| tables << table.values.first }
tables.each do |table|
puts "Truncating #{table}"
connection.real_query("truncate #{table}")
end
connection.close()
end
end
end
@git_help = Sake::Git.new()
Rake.application.top_level()
Something went wrong with that request. Please try again.