Skip to content

Commit 08d7708

Browse files
committed
Merge pull request #90 from dongweiming/cleanup_branch
Add cleanup_branch.py
2 parents 3f31b63 + 2449e95 commit 08d7708

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tools/cleanup_branch.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding=utf-8
2+
import sys
3+
from subprocess import check_output, call
4+
5+
6+
def main(date):
7+
output = check_output('git branch|grep -v master', shell=True)
8+
for branch in output.split('\n'):
9+
branch = branch.strip()
10+
if '*' in branch:
11+
continue
12+
p = check_output(
13+
'git log --since="{0}" -s {1}'.format(date, branch), shell=True)
14+
if not p:
15+
call('git branch -D {}'.format(branch), shell=True)
16+
call('git push --delete --no-verify origin {}'.format(branch),
17+
shell=True)
18+
19+
20+
if __name__ == '__main__':
21+
if len(sys.argv) != 2:
22+
date_ = '2.weeks'
23+
else:
24+
date_ = sys.argv[1]
25+
main(date_)

0 commit comments

Comments
 (0)