Class: GitBranchCleaner::Cleanuper
- Inherits:
-
Object
- Object
- GitBranchCleaner::Cleanuper
- Defined in:
- lib/git_branch_cleaner.rb
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(force) ⇒ Cleanuper
constructor
A new instance of Cleanuper.
Constructor Details
#initialize(force) ⇒ Cleanuper
Returns a new instance of Cleanuper.
7 8 9 |
# File 'lib/git_branch_cleaner.rb', line 7 def initialize(force) @force = force end |
Instance Method Details
#execute! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/git_branch_cleaner.rb', line 11 def execute! `git fetch` branches = `git branch -r`.split("\n") branches.reject! { |branch| `git branch --contains #{branch}` =~ /master/ } branches.map! { |branch| [branch.split('/')[0].strip, branch.split('/')[1].strip] } branches.each do |remote, branch_name| confirmed = @force unless confirmed input = ask("Are you sure you want to delete branch #{branch_name} on remote #{remote}? (Y/n)") confirmed = input =~ /[Yy]/ || input.empty? end if confirmed `git push #{Shellwords.escape(remote)} :#{Shellwords.escape(branch_name)}` end end end |