Sha256: d92fee59fe10f42ac026122ffd585625efc9b23cc2d850257fc27f37de9cb552

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

require 'git-utils/command'

class DeleteRemoteBranch < Command

  def parser
    OptionParser.new do |opts|
      opts.banner = "Usage: git delete-remote-branch <branch>"
      opts.on("-o", "--override", "override unsafe delete") do |opt|
        self.options.override = opt
      end
      opts.on_tail("-h", "--help", "this usage guide") do
        puts opts.to_s; exit 0
      end
    end
  end

  def delete_safely?
    command = "git log ..origin/#{target_branch} 2> /dev/null"
    system(command) && `#{command}`.strip.empty?
  end

  # Returns a command appropriate for executing at the command line
  def cmd
    if delete_safely? || options.override
      c  = ["git push origin :#{target_branch}"]
      c << argument_string(unknown_options) unless unknown_options.empty?
      c.join(" ")
    else
      $stderr.puts "Target branch contains unmerged commits."
      $stderr.puts "Please cherry-pick the commits or merge the branch again."
      $stderr.puts "Use -o or --override to override."
    end
  end

  private

    # Returns the name of the branch to be deleted.
    def target_branch
      self.known_options.first
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
git-utils-0.6.2 lib/git-utils/delete_remote_branch.rb
git-utils-0.6.1 lib/git-utils/delete_remote_branch.rb
git-utils-0.6.0 lib/git-utils/delete_remote_branch.rb
git-utils-0.5.10 lib/git-utils/delete_remote_branch.rb
git-utils-0.5.9 lib/git-utils/delete_remote_branch.rb
git-utils-0.5.8 lib/git-utils/delete_remote_branch.rb
git-utils-0.5.7 lib/git-utils/delete_remote_branch.rb
git-utils-0.5.6 lib/git-utils/delete_remote_branch.rb
git-utils-0.5.5 lib/git-utils/delete_remote_branch.rb