Skip to content

Instantly share code, notes, and snippets.

@anotherjesse
Forked from defunkt/gist:4169
Created August 6, 2008 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anotherjesse/4294 to your computer and use it in GitHub Desktop.
Save anotherjesse/4294 to your computer and use it in GitHub Desktop.
# by bryan helmkamp with slight modification by chris wanstrath
# from http://www.brynary.com/2008/8/3/our-git-deployment-workflow
# I DO NOT RECOMMEND USING THIS WORKFLOW - IT DESTROYS HISTORY! - jesse andrews
module GitCommands
extend self
def diff_staging
`git fetch`
puts `git diff origin/production origin/staging`
end
def tag_staging(branch_name)
verify_safe_and_clean
`git branch -f staging origin/#{branch_name}`
`git push -f origin staging`
`git branch -D staging`
end
def tag_production
verify_safe_and_clean
`git branch -f production origin/staging`
`git push -f origin production`
`git branch -D production`
end
def branch_production(branch_name)
verify_safe_and_clean
`git branch -f #{branch_name} origin/production --no-track`
`git checkout #{branch_name}`
`git push origin #{branch_name}`
end
protected
def verify_safe_and_clean
`git fetch`
return if `git status` =~ /working directory clean/
raise "Must have clean working directory"
end
end
namespace :tag do
desc <<-DESC
Update the staging branch to prepare for a staging deploy.
Defaults to master. Optionally specify a BRANCH=name
DESC
task :staging do
branch_name = ENV['BRANCH'] || "master"
GitCommands.tag_staging(branch_name)
end
desc "Update the remove production branch to prepare for a release"
task :production => ['diff:staging'] do
GitCommands.tag_production
end
end
namespace :diff do
desc "Show the differences between the staging branch and the production branch"
task :staging do
GitCommands.diff_staging
end
end
namespace :branch do
desc "Branch from production for tweaks or bug fixs. Specify BRANCH=name"
task :production do
branch_name = ENV['BRANCH']
raise "You must specify a branch name using BRANCH=name" unless branch_name
GitCommands.branch_production
end
end
namespace :deploy do
desc "Tag and deploy staging"
task :staging => "tag:staging" do
`cap staging deploy:long`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment