-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepo_report.xsh
More file actions
85 lines (69 loc) · 2.96 KB
/
Copy pathrepo_report.xsh
File metadata and controls
85 lines (69 loc) · 2.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import json
import sys
import time
import yaml
from pathlib import Path
from subprocess import CalledProcessError
from xonsh.dirstack import with_pushd
import sys
$XONSH_SUBPROC_CMD_RAISE_ERROR = False
$XONSH_TRACE_SUBPROC = True
$XONSH_TRACEBACK_LOGFILE = 'error.log'
def extract_git_shas():
headsha = $(git rev-parse HEAD).strip()
describe = $(git describe --tags --abbrev=11 --long --dirty --always).strip()
return {'head': headsha, 'describe': describe}
build_order = []
for order in sorted(Path('build_order.d').glob('[!.]*yaml')):
with open(order) as fin:
build_order += list(yaml.safe_load_all(fin))
with open('all_repos.yaml') as fin:
checkouts = list(yaml.safe_load_all(fin))
local_checkouts = {co['name']: co for co in checkouts}
out = {}
for step in build_order:
if step['kind'] != 'source_install':
continue
lc = local_checkouts[step['proj_name']]
# get the working directory
step['wd'] = lc['local_checkout']
# set the default branch
if lc['primary_remote']['vc'] != 'git':
continue
upstream_remote = next(
n for n, r in lc['remotes'].items() if r['url'] == lc['primary_remote']['url']
)
upstream_branch = step['default_branch']
def foo(upstream_branch, checkout):
with with_pushd(checkout):
with ${...}.swap(XONSH_SUBPROC_CMD_RAISE_ERROR=False):
tracking = !(git rev-parse --abbrev-ref --symbolic-full-name '@{u}')
has_tracking = bool(tracking)
tracking_branch = tracking.output.strip()
del tracking
with ${...}.swap(XONSH_SUBPROC_CMD_RAISE_ERROR=True):
cur_branch = $(git branch --show-current).strip()
upstream = f'{upstream_remote}/{upstream_branch}'
with ${...}.swap(XONSH_SUBPROC_CMD_RAISE_ERROR=False):
is_merged = bool(!(git merge-base --is-ancestor HEAD @(upstream)))
shas = extract_git_shas()
return locals()
out[step['proj_name']] = foo(upstream_branch, lc['local_checkout'])
extra_remotes = []
for k, v in out.items():
off_dflt_branch = v['cur_branch'] != v['upstream_branch']
dirty_src = 'dirty' in v['shas']['describe']
if off_dflt_branch or dirty_src:
print(f"{k} ({v['checkout']})")
if off_dflt_branch:
print(f" default: {v['upstream_branch']}")
print(f" on: {v['cur_branch']} [{v['shas']['describe']}]({v['tracking_branch'] if v['has_tracking'] else '-'})")
if v['has_tracking']:
remote_name, *junk = v['tracking_branch'].partition('/')
extra_remotes.append(
{'proj_name': k, 'branch': v['cur_branch'], 'remote': local_checkouts[k]['remotes'][remote_name], 'remote_name': remote_name}
)
if dirty_src:
print(" DIRTY")
with open('extra_remotes.yaml', 'w') as fout:
yaml.dump_all(sorted(extra_remotes, key=lambda x: x['proj_name']), fout)