Class: DeleteRemoteBranch
- 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
-
#cmd ⇒ Object
Returns a command appropriate for executing at the command line.
- #delete_safely? ⇒ Boolean
- #parser ⇒ Object
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
#cmd ⇒ Object
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? || .override c = ["git push origin :#{target_branch}"] c << argument_string() unless .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
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 |
#parser ⇒ Object
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. = "Usage: git delete-remote-branch <branch>" opts.on("-o", "--override", "override unsafe delete") do |opt| self..override = opt end opts.on_tail("-h", "--help", "this usage guide") do puts opts.to_s; exit 0 end end end |