-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfind-upstream
More file actions
executable file
·48 lines (41 loc) · 1.54 KB
/
Copy pathfind-upstream
File metadata and controls
executable file
·48 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
'''
This script shows which local branches and github/* remote tracking branches
have already been cherry-picked into origin/master.
It will then print commands that can be used to prune these branches. This
script makes no modifications; it is read-only.
'''
import re
import subprocess
def get_output(cmd):
return subprocess.check_output(cmd.split(), text=True)
cmd = "git for-each-ref --format=%(refname) refs/heads/* refs/remotes/github/*"
branches = get_output(cmd)
nukable = set([])
for branch in branches.splitlines():
print("\r"+" "*70 + f"\rChecking {branch}", end="")
cmd=f"git log --decorate --oneline --cherry-mark --right-only origin/master...{branch}"
output = get_output(cmd)
if all(x.startswith('= ') for x in output.splitlines()):
m = re.match(r'^= [0-9a-f]+ \(([^\)]*)\)', output)
if not m:
#print(f"No match: {output.rstrip()}")
continue
#print(output)
decorations = m.group(1)
if decorations.startswith('HEAD -> '):
decorations = decorations[8:]
nukable |= set(decorations.split(', '))
print("\r"+" "*70+"\rDone.")
local_branches = ' '.join(x for x in nukable if not x.startswith('github/'))
if local_branches:
print("To prune local branches:")
print(f" git branch -D {local_branches}")
else:
print("No local branches to prune.")
remote_branches = ' '.join(x[7:] for x in nukable if x.startswith('github/'))
if remote_branches:
print("To prune remote branches:")
print(f" git push --delete github {remote_branches}")
else:
print("No remote branches to prune.")