Sha256: d1c53cf9e631e6fc89bd54f51d328c5b9a369a52943239994ec29970967ddd82

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

#!/usr/bin/env ruby
require 'optparse'

# Deletes (almost) every branch already merged into current branch.
# Exceptions are `master`, `staging`, and `development`, and the current
# branch, which are preserved. We also support custom configuration via the
# `~/.git-cleanup-preserved` file.

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: yoga [options]"

  opts.on("-r", "Clean up remote branches") do
    options[:remote] = true
  end
end.parse!

preserved = "master|staging|development"
preserved_file = File.join(Dir.home, '.git-cleanup-preserved')
if File.exist?(preserved_file)
  additional_preserved = File.read(preserved_file).strip.split("\n")
  unless additional_preserved.empty?
    preserved += '|' + additional_preserved.join('|')
  end
end
cmd  = %(git branch --merged | grep -v "\*" | egrep -v "(#{preserved})" | )
if options[:remote]
  cmd += "sed -e 's/origin\\//:/' | xargs git push origin"
  cmd.sub!('git branch', 'git branch -r')
else
  cmd += 'xargs -n 1 git branch -d'
end
system cmd

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
git-utils-0.6.4 bin/git-cleanup
git-utils-0.6.3 bin/git-cleanup
git-utils-0.6.2 bin/git-cleanup
git-utils-0.6.1 bin/git-cleanup