aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/tools/dev/bin/clean-branches.py
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-09-09 22:15:21 -0700
committerAshlee Young <ashlee@onosfw.com>2015-09-09 22:15:21 -0700
commit13d05bc8458758ee39cb829098241e89616717ee (patch)
tree22a4d1ce65f15952f07a3df5af4b462b4697cb3a /framework/src/onos/tools/dev/bin/clean-branches.py
parent6139282e1e93c2322076de4b91b1c85d0bc4a8b3 (diff)
ONOS checkin based on commit tag e796610b1f721d02f9b0e213cf6f7790c10ecd60
Change-Id: Ife8810491034fe7becdba75dda20de4267bd15cd
Diffstat (limited to 'framework/src/onos/tools/dev/bin/clean-branches.py')
-rwxr-xr-xframework/src/onos/tools/dev/bin/clean-branches.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/framework/src/onos/tools/dev/bin/clean-branches.py b/framework/src/onos/tools/dev/bin/clean-branches.py
new file mode 100755
index 00000000..3de7cb70
--- /dev/null
+++ b/framework/src/onos/tools/dev/bin/clean-branches.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+from subprocess import check_output
+import sys
+
+def get_merged_branches_by_change_id():
+ '''a list of merged branches, by change id excluding support branches and master'''
+ raw_changeIds = check_output('git log origin/master | grep -i change-id | awk {\' print $2 \'}', shell=True)
+ changeIds = [b.strip() for b in raw_changeIds.split('\n') if b.strip()]
+ raw_branches = check_output('git branch -a', shell=True)
+ branches = [b.strip() for b in raw_branches.split('\n')
+ if b.strip() and not b.startswith('*') and \
+ not b.strip().startswith('onos') and not b.strip().startswith('remotes') and b.strip() != 'master']
+ to_delete = []
+ for branch in branches:
+ raw_local_change_ids = check_output('git show %s | grep -i change-id | awk {\' print $2 \'}' % branch, shell=True)
+ local_change_ids = [ b.strip() for b in raw_local_change_ids.split('\n') if b.strip() ]
+ for local_change_id in local_change_ids:
+ if local_change_id in changeIds and branch not in to_delete:
+ to_delete.append(branch)
+
+ return to_delete
+
+
+def delete_branch(branch):
+ return check_output('git branch -D %s' % branch, shell=True).strip()
+
+
+if __name__ == '__main__':
+ dry_run = '--confirm' not in sys.argv
+ one_by_one = '--one-by-one' in sys.argv
+ to_delete = get_merged_branches_by_change_id()
+ if len(to_delete) == 0:
+ print "Nothing to clean"
+ sys.exit(0)
+ for branch in to_delete:
+ if dry_run:
+ print branch
+ else:
+ if one_by_one:
+ print 'Do you want to delete branch %s [y/N]' % branch
+ ans = raw_input()
+ if ans == 'y' or ans == 'Y':
+ print delete_branch(branch)
+ else:
+ print delete_branch(branch)
+
+ if dry_run:
+ print '*****************************************************************'
+ print 'Did not actually delete anything yet, pass in --confirm to delete'
+ print