From 797459750f4b5e84d1ea252556c9c020785635a4 Mon Sep 17 00:00:00 2001 From: sisungo Date: Wed, 10 Jun 2026 03:06:21 +0800 Subject: [PATCH] feat (lib): add source_git Signed-off-by: sisungo --- lib/make.py | 4 ++++ lib/sources.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/make.py b/lib/make.py index 9f41a54..1c40374 100644 --- a/lib/make.py +++ b/lib/make.py @@ -59,3 +59,7 @@ def block_hook(hook: str): def source_url(url: str): sources.source_url(url) + + +def source_git(url: str, branch: str | None = None): + sources.source_git(url, branch) diff --git a/lib/sources.py b/lib/sources.py index f6e447b..eff3475 100644 --- a/lib/sources.py +++ b/lib/sources.py @@ -1,4 +1,5 @@ import os +import subprocess import sys import tarfile import urllib.parse @@ -109,3 +110,20 @@ def source_url(url: str): tar.extractall(extract_dir) with open("./target/sources.tag", "wt+") as file: file.write(sources_dir) + + +def _git_repo_name(url: str) -> str: + return url.split("/")[-1].replace(".git", "") + + +def source_git(url: str, branch: str | None = None): + source_path = os.getcwd() + "/target/" + _git_repo_name(url) + if os.path.exists("./target/sources.tag"): + return + cmdline = ["git", "clone", "--depth=1"] + if branch: + cmdline += ["-b", branch] + cmdline += [url, source_path] + subprocess.run(cmdline, check=True) + with open("./target/sources.tag", "wt+") as file: + file.write(source_path) -- 2.55.0