Created
July 21, 2020 16:03
-
-
Save bigs/a1391ab8d3430a40d1225fa40f894083 to your computer and use it in GitHub Desktop.
git hatchet -- excise old branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash ruby | |
require "open3" | |
sigint_caught = false | |
Signal.trap("INT") do | |
sigint_caught = true | |
throw :sigint | |
end | |
def proxy_failure!(o, e, s) | |
if s.exitstatus != 0 | |
STDOUT.write(o) | |
STDERR.write(e) | |
exit s.exitstatus | |
end | |
end | |
o, e, s = Open3.capture3("git status") | |
proxy_failure!(o, e, s) | |
o, e, s = Open3.capture3("git branch --list") | |
proxy_failure!(o, e, s) | |
branches = o.split("\n").map(&:strip).map { |b| b.gsub(/^\*\s+/, '') } | |
catch :sigint do | |
branches.each do |branch| | |
print "Delete branch \"#{branch}\"? " | |
if gets.strip.downcase == "y" | |
puts "--> Deleting \"#{branch}\"" | |
o, e, s = Open3.capture3("git branch -D #{branch}") | |
proxy_failure!(o, e, s) | |
else | |
puts "--x Leaving \"#{branch}\"" | |
end | |
end | |
end | |
if sigint_caught | |
puts | |
puts "--x Caught SIGINT, exiting..." | |
exit | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment