aboutsummaryrefslogtreecommitdiff
path: root/https-sync-repos.py
blob: 0e78afe3843af6001411f1b01288c37cc02ec2c7 (plain) (blame)
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
#!/usr/bin/env python3

# Synchronize Cryptech git repositories by extracting URLs from the
# Alpha release engineering repository's .gitmodules file.  This
# yields the same tree structure as used by releng/alpha, but without
# the git submodule complexities.

import sys, urllib.request, urllib.parse, subprocess
from configparser import ConfigParser, DEFAULTSECT
from pathlib import Path

errs = 0

url = "https://git.cryptech.is/releng/alpha/plain/.gitmodules"
cfg = ConfigParser(interpolation = None)
cfg.read_string(urllib.request.urlopen(url).read().decode())

for section in cfg:
    if section == DEFAULTSECT:
        continue

    url = cfg[section]["url"]
    repo = Path(urllib.parse.urlparse(url).path).relative_to("/").with_suffix("")

    try:
        if repo.is_dir():
            subprocess.run(("git", "-C", repo, "fetch", "--all", "--prune"), check = True)
            subprocess.run(("git", "-C", repo, "merge", "--ff-only"), check = True)
        else:
            repo.parent.mkdir(parents = True, exist_ok = True)
            subprocess.run(("git", "-C", repo.parent, "clone", url), check = True)

    except:
        print("** Error for repo", repo)
        errs += 1

sys.exit(errs)