#!/usr/bin/env ruby

# Simple helper class to iterate over the git branches in your working directory and offer to delete them.
class InteractiveGitBranchDeleter
  require 'open3'

  def self.perform
    stdout, stderr, status = Open3.capture3("git branch")
    branches = stdout.split

    branches.each do |branch|
      print "\n Delete \e[31m#{branch}?\e[0m (y/n) "
      response = gets.chomp.strip.downcase

      if response == 'y'
        command = "git branch -d #{branch}"
        stdout, stderr, status = Open3.capture3(command)
      end
    end
  end
end

# Entrypoint
if __FILE__ == $0
  InteractiveGitBranchDeleter.perform
end

#!/usr/bin/env ruby

# Simple helper class to iterate over the git branches in your working directory and offer to delete them.
class InteractiveGitBranchDeleter
  require 'open3'

  def self.perform
    stdout, stderr, status = Open3.capture3("git branch")
    branches = stdout.split

    branches.each do |branch|
      print "\n Delete \e[31m#{branch}?\e[0m (y/n) "
      response = gets.chomp.strip.downcase

      if response == 'y'
        command = "git branch -D #{branch}"
        stdout, stderr, status = Open3.capture3(command)
      end
    end
  end
end

# Entrypoint
if __FILE__ == $0
  InteractiveGitBranchDeleter.perform
end

Allow deletion of unmerged branches
Allow deletion of unmerged branches

Calling git branch with the `-d` flag will only delete a branch if it
has been fully merged with its parent (usually master). In this case, if
the user explicitly chooses to delete a local branch, we want to honour
this request regardless of whether the branch has been merged.

This commit swaps `-d` with `-D`, which will proceed with the deletion
regardless of merge status.
