diff --git a/spec/support/outputs/git_ensure_pushed.txt b/spec/support/outputs/git_ensure_pushed.txt new file mode 100644 index 00000000..c40990e4 --- /dev/null +++ b/spec/support/outputs/git_ensure_pushed.txt @@ -0,0 +1,15 @@ +echo "-----> Ensuring everything is pushed to git" +if \[ \$\(git branch --list master \| wc -l\) -eq 0 \]; then + echo "! Branch master doesn't exist" + exit 1 +fi + +if \[ \$\(git branch -r --list origin/master \| wc -l\) -eq 0 \]; then + echo "! Branch origin/master doesn't exist" + exit 1 +fi + +if \[ \$\(git log origin/master..master \| wc -l\) -ne 0 \]; then + echo "! Your branch master needs to be pushed to origin before deploying" + exit 1 +fi \ No newline at end of file diff --git a/spec/tasks/git_spec.rb b/spec/tasks/git_spec.rb index f693575a..e099b083 100644 --- a/spec/tasks/git_spec.rb +++ b/spec/tasks/git_spec.rb @@ -18,4 +18,10 @@ expect { invoke_all }.to output(output_file('git_revision')).to_stdout end end + + describe 'git:ensure_pushed' do + it 'git ensure pushed' do + expect { invoke_all }.to output(output_file('git_ensure_pushed')).to_stdout + end + end end diff --git a/tasks/mina/git.rb b/tasks/mina/git.rb index 60371799..52e27875 100644 --- a/tasks/mina/git.rb +++ b/tasks/mina/git.rb @@ -4,6 +4,8 @@ set :remove_git_dir, true set :remote, 'origin' set :git_not_pushed_message, -> { "Your branch #{fetch(:branch)} needs to be pushed to #{fetch(:remote)} before deploying" } +set :git_local_branch_missing_message, -> { "Branch #{fetch(:branch)} doesn't exist" } +set :git_remote_branch_missing_message, -> { "Branch #{fetch(:remote)}/#{fetch(:branch)} doesn't exist" } namespace :git do desc 'Clones the Git repository to the current path.' @@ -48,6 +50,16 @@ run :local do comment %{Ensuring everything is pushed to git} command %{ + if [ $(git branch --list #{fetch(:branch)} | wc -l) -eq 0 ]; then + echo "! #{fetch(:git_local_branch_missing_message)}" + exit 1 + fi + + if [ $(git branch -r --list #{fetch(:remote)}/#{fetch(:branch)} | wc -l) -eq 0 ]; then + echo "! #{fetch(:git_remote_branch_missing_message)}" + exit 1 + fi + if [ $(git log #{fetch(:remote)}/#{fetch(:branch)}..#{fetch(:branch)} | wc -l) -ne 0 ]; then echo "! #{fetch(:git_not_pushed_message)}" exit 1