class DeleteRemoteBranch

Public Instance Methods

cmd() click to toggle source

Returns a command appropriate for executing at the command line.

# File lib/git-utils/delete_remote_branch.rb, line 23
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
delete_safely?() click to toggle source
# File lib/git-utils/delete_remote_branch.rb, line 17
def delete_safely?
  command = "git log ..origin/#{target_branch} 2> /dev/null"
  system(command) && `#{command}`.strip.empty?
end
parser() click to toggle source
# File lib/git-utils/delete_remote_branch.rb, line 5
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

Private Instance Methods

target_branch() click to toggle source

Returns the name of the branch to be deleted.

# File lib/git-utils/delete_remote_branch.rb, line 38
def target_branch
  self.known_options.first
end