| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #!/usr/bin/env python3
- # vim: set noet sw=4 ts=4:
- import subprocess
- import sys
- import time
- force = len(sys.argv) == 2 and sys.argv[1] == '-f'
- output = subprocess.check_output(['git', 'branch', '--merged', 'origin/master', '-a'], universal_newlines=True)
- branches = []
- for line in output.split('\n'):
- if not line.startswith(' ') or ' -> ' in line:
- continue
- line = line[2:]
- if line.startswith('remotes/origin/'):
- line = line[8:]
- branches.append(line)
- day_seconds = 24 * 60 * 60
- now = time.time()
- cutoff = now - 30 * day_seconds
- for branch in branches:
- if branch == 'origin/master':
- continue
- output = subprocess.check_output(['git', 'show', branch, '-s', '--format=%at %ct'], universal_newlines=True)
- if not output.endswith('\n'):
- raise Exception()
- timestamp = max(map(int, output[:-1].split(' ', 2)))
- if timestamp > cutoff:
- print('ignoring', branch)
- continue
- print('deleting %s (%.1f days old)' % (branch, (now - timestamp) / day_seconds))
- if branch.startswith('origin/'):
- subprocess.check_call(['git', 'push', 'origin', ':' + branch[7:]])
- else:
- subprocess.check_call(['git', 'branch', '-d', branch])
|