Browse files

Create Kumade::Git and Kumade::Git#push

  • Loading branch information...
1 parent fcb02cc commit c2015099102819b37a61c8e5ee904d5e07df334f @tapajos tapajos committed Aug 29, 2011
Showing with 51 additions and 11 deletions.
  1. +2 −2 README.md
  2. +2 −2 features/kumade_executable.feature
  3. +1 −0 lib/kumade.rb
  4. +3 −6 lib/kumade/deployer.rb
  5. +42 −0 lib/kumade/git.rb
  6. +1 −1 spec/kumade/deployer_spec.rb
View
4 README.md
@@ -99,7 +99,7 @@ Yes. To indicate that a particular app is using Cedar, run with the -c flag:
To git@heroku.com:staging-sushi.git
a465afd..bc8932b master -> master
==> - true
- ==> Force pushed master -> heroku-staging
+ ==> Pushed master -> heroku-staging
==> + bundle exec heroku rake db:migrate --app staging-sushi
... Postgres output removed ...
==> - false
@@ -116,7 +116,7 @@ Yes. To indicate that a particular app is using Cedar, run with the -c flag:
==> Rake passed
==> Packaged assets with Jammit
==> Pushed master -> origin
- ==> Force pushed master -> heroku-staging
+ ==> Pushed master -> heroku-staging
==> Migrated staging-sushi
==> Deployed to: heroku-staging
View
4 features/kumade_executable.feature
@@ -26,7 +26,7 @@ Feature: Kumade executable
==> Pushed master -> origin
run git branch deploy
run git push -f pretend-staging deploy:master
- ==> Force pushed master -> pretend-staging
+ ==> Pushed deploy:master -> pretend-staging
==> Migrated pretend-staging-app
run git checkout master && git branch -D deploy
==> Deployed to: pretend-staging
@@ -57,7 +57,7 @@ Feature: Kumade executable
==> Pushed new_branch -> origin
run git branch deploy
run git push -f pretend-staging deploy:master
- ==> Force pushed new_branch -> pretend-staging
+ ==> Pushed deploy:master -> pretend-staging
==> Migrated pretend-staging-app
run git checkout new_branch && git branch -D deploy
==> Deployed to: pretend-staging
View
1 lib/kumade.rb
@@ -1,6 +1,7 @@
require 'rake'
require 'thor'
+require 'kumade/git'
require 'kumade/deployer'
require 'kumade/runner'
require 'kumade/railtie'
View
9 lib/kumade/deployer.rb
@@ -9,6 +9,7 @@ def initialize(environment = 'staging', pretending = false, cedar = false)
@pretending = pretending
@branch = current_branch
@cedar = cedar
+ @git = Git.new(pretending, environment)
end
def deploy
@@ -26,18 +27,14 @@ def pre_deploy
end
def sync_github
- run_or_error("git push origin #{@branch}",
- "Failed to push #{@branch} -> origin")
- success("Pushed #{@branch} -> origin")
+ @git.push(@branch)
end
def sync_heroku
unless branch_exist?(DEPLOY_BRANCH)
run_or_error("git branch deploy", "Failed to create #{DEPLOY_BRANCH}")
end
- run_or_error("git push -f #{environment} #{DEPLOY_BRANCH}:master",
- "Failed to force push #{DEPLOY_BRANCH} -> #{environment}/master")
- success("Force pushed #{@branch} -> #{environment}")
+ @git.push("#{DEPLOY_BRANCH}:master", environment, true)
end
def heroku_migrate
View
42 lib/kumade/git.rb
@@ -0,0 +1,42 @@
+module Kumade
+ class Git < Thor::Shell::Color
+ def initialize(pretending, environment)
+ super()
+ @pretending = pretending
+ @environment = environment
+ end
+
+ def push(branch, remote = 'origin', force = false)
+ command = ["git push"]
+ command << "-f" if force
+ command << remote
+ command << branch
+ command = command.join(" ")
+ run_or_error([command], "Failed to push #{branch} -> #{remote}")
+ success("Pushed #{branch} -> #{remote}")
+ end
+
+ def run_or_error(commands, error_message)
+ all_commands = [commands].flatten.join(' && ')
+ if @pretending
+ say_status(:run, all_commands)
+ else
+ error(error_message) unless run(all_commands)
+ end
+ end
+
+ def run(command, config = {})
+ say_status :run, command
+ config[:capture] ? `#{command}` : system("#{command}")
+ end
+
+ def error(message)
+ say("==> ! #{message}", :red)
+ exit 1
+ end
+
+ def success(message)
+ say("==> #{message}", :green)
+ end
+ end
+end
View
2 spec/kumade/deployer_spec.rb
@@ -148,7 +148,7 @@
it "prints a success message" do
subject.should_receive(:success).
- with("Force pushed master -> #{environment}")
+ with("Pushed master -> #{environment}")
subject.sync_heroku
end

0 comments on commit c201509

Please sign in to comment.