-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for deleting local merged branches.
- Loading branch information
Chiel ten Brinke
committed
Jun 16, 2016
1 parent
2ceef18
commit 8be141d
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Delete local branches that are merged into master. | ||
Before each operation, the user is asked for confirmation. | ||
""" | ||
import argparse | ||
|
||
# This dependency can be found on github: https://github.com/Chiel92/python-shellout | ||
from pyshellout import get, out, confirm | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('master', | ||
help='Name of the master branch. Defaults to \'master\'.', | ||
nargs='?', default='master') | ||
args = parser.parse_args() | ||
master = args.master | ||
|
||
|
||
# Get merged branches | ||
merged_branches = [line.strip() for line in | ||
get(r'git branch --merged {}', master, critical=True).n] | ||
merged_branches = [branch for branch in merged_branches | ||
if branch != '' and not '*' in branch and not branch == master] | ||
|
||
print('Merged local branches:') | ||
for branch in merged_branches: | ||
print(' ' + branch) | ||
|
||
|
||
print() | ||
for branch in merged_branches: | ||
if confirm('Delete local branch {}?', branch): | ||
out('git branch -d {}', branch) | ||
|