diff --git a/lib/capistrano/deploytags.rb b/lib/capistrano/deploytags.rb index 5eebdee..cbfc673 100644 --- a/lib/capistrano/deploytags.rb +++ b/lib/capistrano/deploytags.rb @@ -1,6 +1,21 @@ # Ensure deploy tasks are loaded before we run require 'capistrano/deploy' +module SSHKit + class CommandMap + def defaults + Hash.new do |hash, command| + if %w{if test time exec}.include? command.to_s || File.executable?('/usr/bin/env') + hash[command] = command.to_s + else + #hash[command] = "/usr/bin/env #{command}" + hash[command] = "#{command}" + end + end + end + end +end + # Load extra tasks into the deploy namespace load File.expand_path("../tasks/deploytags.rake", __FILE__) diff --git a/lib/capistrano/tasks/deploytags.rake b/lib/capistrano/tasks/deploytags.rake index de1d35d..92b0905 100644 --- a/lib/capistrano/tasks/deploytags.rake +++ b/lib/capistrano/tasks/deploytags.rake @@ -1,47 +1,52 @@ namespace :deploy do desc 'prepare git tree so we can tag on successful deployment' before :deploy, :prepare_tree do - if ENV['NO_DEPLOYTAGS'] || fetch(:no_deploytags, false) - info "[deploytags] Skipping deploytags" - else - branch = fetch(:branch, false) - stage = fetch(:stage, false) + SSHKit.config.default_env = {} + run_locally do + if ENV['NO_DEPLOYTAGS'] || fetch(:no_deploytags, false) + info "[deploytags] Skipping deploytags" + else + branch = fetch(:branch, false) + stage = fetch(:stage, false) - unless branch && stage - error 'capistrano-deploytags requires that :branch and :stage be defined' - raise 'define :branch and :stage' + unless branch && stage + error 'capistrano-deploytags requires that :branch and :stage be defined' + raise 'define :branch and :stage' + end + + execute :git, "fetch #{fetch(:git_remote, 'origin')}" + + diff_output = capture :git, "diff #{branch} --shortstat" + + unless diff_output.empty? + error "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first" + raise 'Dirty git tree' + end + + execute :git, "checkout #{branch}" + info "Pulling from #{branch}" + execute :git, "pull #{fetch(:git_remote, 'origin')} #{branch}" end - - system :git, "fetch #{fetch(:git_remote, 'origin')}" - - diff_output = capture :git, "diff #{branch} --shortstat" - - unless diff_output.empty? - error "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first" - raise 'Dirty git tree' - end - - system :git, "checkout #{branch}" - info "Pulling from #{branch}" - system :git, "pull #{fetch(:git_remote, 'origin')} #{branch}" end end desc 'add git tags for each successful deployment' after :cleanup, :tagdeploy do - if ENV['NO_DEPLOYTAGS'] || fetch(:no_deploytags, false) - info "[deploytags] Skipping deploytags" - else - tag_name = ENV['CUSTOM_DEPLOYTAG'] || fetch(:custom_deploytag) || CapistranoDeploytags::Helper.git_tag_for(fetch(:stage)) - latest_revision = fetch(:current_revision) - commit_message = CapistranoDeploytags::Helper.commit_message(latest_revision, fetch(:stage)) + run_locally do + if ENV['NO_DEPLOYTAGS'] || fetch(:no_deploytags, false) + info "[deploytags] Skipping deploytags" + else + tag_name = ENV['CUSTOM_DEPLOYTAG'] || fetch(:custom_deploytag) || CapistranoDeploytags::Helper.git_tag_for(fetch(:stage)) + latest_revision = fetch(:current_revision) + commit_message = CapistranoDeploytags::Helper.commit_message(latest_revision, fetch(:stage)) - unless fetch(:sshkit_backend) == SSHKit::Backend::Printer # unless --dry-run flag present - system :git, "tag -a #{tag_name} -m \"#{commit_message}\" #{latest_revision}" - system :git, "push #{fetch(:git_remote, 'origin')} #{tag_name}" + unless fetch(:sshkit_backend) == SSHKit::Backend::Printer # unless --dry-run flag present + execute :git, "tag -a #{tag_name} -m \"#{commit_message}\" #{latest_revision}" + execute :git, "push #{fetch(:git_remote, 'origin')} #{tag_name}" + end + + info "[cap-deploy-tagger] Tagged #{latest_revision} with #{tag_name}" end - - info "[cap-deploy-tagger] Tagged #{latest_revision} with #{tag_name}" end end end