From 11e1eec172a3f6460123197a448c11e04f9296c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 20 Dec 2024 23:48:33 +0100 Subject: [PATCH] Fix handling "branch" set to a commit hash There is --git-commit option for get-and-verify-source.py already. Use its implementation, but keep verifying tags. For that, they need to be fetched. --- .../fetch/scripts/get-and-verify-source.py | 4 +++- tests/test_cli.py | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/qubesbuilder/plugins/fetch/scripts/get-and-verify-source.py b/qubesbuilder/plugins/fetch/scripts/get-and-verify-source.py index ec23c49c..a194b30f 100755 --- a/qubesbuilder/plugins/fetch/scripts/get-and-verify-source.py +++ b/qubesbuilder/plugins/fetch/scripts/get-and-verify-source.py @@ -183,7 +183,8 @@ def main(args): if repo.exists(): shutil.rmtree(repo) try: - if args.git_commit: + looks_like_commit = re.match(r"^[a-fA-F0-9]{40}$", git_branch) + if args.git_commit or looks_like_commit: # git clone can't handle commit reference, use fetch instead repo.mkdir() subprocess.run( @@ -194,6 +195,7 @@ def main(args): ) subprocess.run( ["git", "fetch"] + + (["--tags"] if looks_like_commit else []) + git_options + ["--", git_url, git_branch], capture_output=True, diff --git a/tests/test_cli.py b/tests/test_cli.py index 3fbf4531..d8fb767f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -355,6 +355,29 @@ def test_common_component_fetch_skip_files(artifacts_dir_single): in result ) +def test_common_component_fetch_commit_fresh(artifacts_dir_single): + artifacts_dir = artifacts_dir_single + commit_sha = "0589ae8a242b3be6a1b8985c6eb8900e5236152a" + result = qb_call_output( + DEFAULT_BUILDER_CONF, + artifacts_dir, + "-c", + "core-qrexec", + "-o", + f"+components+core-qrexec:branch={commit_sha}", + "package", + "fetch", + ).decode() + + fetch_artifact = ( + artifacts_dir / + "components/core-qrexec/4.2.20-1/nodist/fetch/source.fetch.yml" + ) + assert fetch_artifact.exists() + with open(fetch_artifact) as f: + info = yaml.safe_load(f.read()) + assert info["git-commit-hash"] == commit_sha + # # Pipeline for core-qrexec and host-fc37