class BranchCleaner

Public Class Methods

clean() click to toggle source
# File lib/branch_cleaner.rb, line 27
def self.clean()
  repo_root = get_repository_root() ; result = $?.success?
  if !result
    abort("Exiting, not in a git repository")
  end
  branches = get_branches()
  branches_to_keep = get_branches_to_keep()
  for branch in branches do
    branch_name = branch.gsub(/^\*?\s*/, '')
    if branches_to_keep.include?(branch_name)
      puts "Skipping branch " + branch_name
    elsif branch.start_with?('*')
      puts "Skipping active branch " + branch_name
    else
      system("git branch -d " + branch_name)
    end
  end
end
get_branches() click to toggle source
# File lib/branch_cleaner.rb, line 12
def self.get_branches()
  `git branch`.split("\n").map {|b| b.strip }
end
get_branches_to_keep() click to toggle source
# File lib/branch_cleaner.rb, line 16
def self.get_branches_to_keep()
  file = get_repository_root() + "/.branches_to_keep"
  keepers = Set.new ["master"]
  if File.exist?(file)
    File.readlines(file).each do |line|
      keepers.add(line.strip)
    end
  end
  return keepers
end
get_current_directory() click to toggle source
# File lib/branch_cleaner.rb, line 4
def self.get_current_directory()
  `pwd`
end
get_repository_root() click to toggle source
# File lib/branch_cleaner.rb, line 8
def self.get_repository_root()
  `git rev-parse --show-toplevel`.strip
end