Skip to content

Commit

Permalink
Fix handling "branch" set to a commit hash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marmarek committed Dec 21, 2024
1 parent 41fa9e8 commit 11e1eec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion qubesbuilder/plugins/fetch/scripts/get-and-verify-source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11e1eec

Please sign in to comment.