Class: DeleteRemoteBranch

Inherits:
Command
  • Object
show all
Defined in:
lib/git-utils/delete_remote_branch.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #known_options, #options, #unknown_options

Instance Method Summary collapse

Methods inherited from Command

#current_branch, #default_branch, #initialize, #origin_url, #parse, #protocol, run!, #run!, #service

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#cmdObject

Returns a command appropriate for executing at the command line.



23
24
25
26
27
28
29
30
31
32
33
# 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?Boolean

Returns:

  • (Boolean)


17
18
19
20
# 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

#parserObject



5
6
7
8
9
10
11
12
13
14
15
# 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