blob: 9487102df1a1c4a34d493c3f15dc85f899642eef [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001#! /usr/bin/env python3
2
3# Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches
4
5import sys
6import os
Andrew Geissler2daf84b2023-03-31 09:57:23 -05007import shutil
Brad Bishopbec4ebc2022-08-03 09:55:16 -04008import subprocess
9import pathlib
10
11def repo_shortname(url):
12 # Taken from Kas (Repo.__getattr__) to ensure the logic is right
13 from urllib.parse import urlparse
14 url = urlparse(url)
15 return ('{url.netloc}{url.path}'
16 .format(url=url)
17 .replace('@', '.')
18 .replace(':', '.')
19 .replace('/', '.')
20 .replace('*', '.'))
21
22repositories = (
23 "https://git.yoctoproject.org/git/poky",
24 "https://git.openembedded.org/meta-openembedded",
25 "https://git.yoctoproject.org/git/meta-virtualization",
Brad Bishopbec4ebc2022-08-03 09:55:16 -040026 "https://github.com/kraj/meta-clang",
27)
28
29if __name__ == "__main__":
30 if "KAS_REPO_REF_DIR" not in os.environ:
31 print("KAS_REPO_REF_DIR needs to be set")
32 sys.exit(1)
33
34 base_repodir = pathlib.Path(os.environ["KAS_REPO_REF_DIR"])
35
36 for repo in repositories:
37 repodir = base_repodir / repo_shortname(repo)
Andrew Geissler2daf84b2023-03-31 09:57:23 -050038
39 if "CI_CLEAN_REPOS" in os.environ:
40 print("Cleaning %s..." % repo)
41 shutil.rmtree(repodir, ignore_errors=True)
42
Brad Bishopbec4ebc2022-08-03 09:55:16 -040043 if repodir.exists():
44 print("Updating %s..." % repo)
Andrew Geissler2daf84b2023-03-31 09:57:23 -050045 subprocess.run(["git", "-C", repodir, "-c", "gc.autoDetach=false", "fetch"], check=True)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040046 else:
47 print("Cloning %s..." % repo)
48 subprocess.run(["git", "clone", "--bare", repo, repodir], check=True)