Skip to content

Instantly share code, notes, and snippets.

@exallium
Created October 19, 2016 13:45
Show Gist options
  • Save exallium/3d570aae540afd5475ab0894e2cda2c8 to your computer and use it in GitHub Desktop.
Save exallium/3d570aae540afd5475ab0894e2cda2c8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import subprocess
EXCLUDE = ["patrick-video-player-integration"]
GET_MERGED_BRANCHES = ["git", "branch", "--merged"]
DELETE_BRANCH = ["git", "branch", "--delete"]
PRUNE_ORIGIN = ["git", "remote", "prune", "origin"]
def runSubProc(proc):
return subprocess.Popen(proc, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
def removeCurrentBranch(branches):
return filter(lambda b: not b.startswith('*') and len(b) != 0, branches)
def trimBranches(branches):
return map(lambda b: b.strip(), branches)
def removeExcludes(branches):
return filter(lambda b: b not in EXCLUDE, branches)
def deleteBranch(branch):
return runSubProc(sum([DELETE_BRANCH, [branch]], []))
out, err = runSubProc(GET_MERGED_BRANCHES)
print '\n'.join([deleteBranch(b)[0] for b in (removeExcludes(trimBranches(removeCurrentBranch(out.split('\n')))))])
print runSubProc(PRUNE_ORIGIN)[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment