Skip to content

Commit

Permalink
ensure git pushed function - code props to @fgarcia
Browse files Browse the repository at this point in the history
  • Loading branch information
devvmh committed Aug 8, 2016
1 parent 738a8b2 commit 5f8cdb8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

desc "Deploys the current version to the server."
task deploy: :environment do
ensure_git_pushed!
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
Expand Down
7 changes: 7 additions & 0 deletions docs/writing_your_own_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ Raises an error if variable is not set
``` ruby
ensure!(:deploy_to)
```

### ensure_git_pushed!
Aborts the build if the local branch has not been pushed to the remote branch.

``` ruby
ensure_git_pushed!(branch: :master, remote: :origin, message: "Your master branch needs to be pushed to origin before deploying")
```
9 changes: 9 additions & 0 deletions lib/mina/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def invoke(task, *args)
Rake::Task[task].reenable
end

def ensure_git_pushed!(opts = {})
branch = opts[:branch] || fetch(:branch)
remote = opts[:remote] || fetch(:remote)
message = opts[:message].to_s ||
"Your branch #{branch} needs to be pushed to #{remote} before deploying"
pending = system "[ $(git log #{remote}/#{branch}..#{branch} | wc -l) -ne 0 ]"
fail message if pending
end

def commands
@commands ||= Commands.new
end
Expand Down

0 comments on commit 5f8cdb8

Please sign in to comment.