Sha256: 3201d3cfc8f8e60427d87bdf18082e5f375893e6e00db978571a0abb945099eb

Contents?: true

Size: 859 Bytes

Versions: 1

Compression:

Stored size: 859 Bytes

Contents

Capistrano::DSL.stages.each do |stage|
  after stage, "check:push"
end

namespace :check do
  task :push do
    next if fetch(:skip_push_check)

    local_branch = `git symbolic-ref --short HEAD`.strip
    track = ` git branch --list --format '%(upstream:track)' #{local_branch}`.strip

    unless track == ""
      case
      when track =~ /\[ahead (\d+)\]/
        n = $~.captures.first.to_i
        warn("=" * 100)
        warn("!!! Local branch `#{local_branch}` is ahead of upstream by #{n} commit(s). Please run `git push`. !!!")
        warn("=" * 100)
        exit 1
      when track =~ /\[behind (\d+)\]/
        n = $~.captures.first.to_i
        warn("=" * 100)
        warn("!!! Local branch `#{local_branch}` is behind of upstream by #{n} commit(s). Please run `git pull`. !!!")
        warn("=" * 100)
        exit 1
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-push_check-0.1.1 lib/capistrano/tasks/push_check.rake