From 0e8c8e221ca762fe2e442f4b2c5a56d390e06537 Mon Sep 17 00:00:00 2001 From: Srikanth Aithal Date: Fri, 26 Sep 2025 16:39:33 +0530 Subject: [PATCH] Add branch/tag handling for tests Enhance wrapper to work with either branch/tag for the tests, along with minor error handling improvements. Signed-off-by: Srikanth Aithal --- avocado-setup.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/avocado-setup.py b/avocado-setup.py index 1a6f11ec..056c21eb 100644 --- a/avocado-setup.py +++ b/avocado-setup.py @@ -229,11 +229,25 @@ def get_repo(repo, basepath): if not isinstance(repo, tuple): repo = (repo, '') + cmd_default_branch = "git ls-remote --symref %s HEAD | grep '^ref:' | awk '{print $2}' | cut -d'/' -f3" % repo[0] + status, default_branch = helper.runcmd(cmd_default_branch, err_str="Failed to find default branch for %s repository:" % repo[0]) + if status != 0: + logger.warning(f"Failed to find default branch for {repo[0]} repository, going ahead assuming master branch as default branch") + default_branch = "master" if repo[1] == '': - branch = "master" + branch = default_branch else: branch = repo[1] - cmd_update = "b=%s;git reset --hard && git checkout master && git remote update && (git branch | grep -w $b && (git switch $b && git pull origin $b --rebase) || (git fetch origin && git switch -c $b origin/$b) || echo \"Error: Could not sync with origin/$b\")" % branch + cmd_istag = "git ls-remote --refs %s %s" % (repo[0], branch) + status, res = helper.runcmd(cmd_istag, err_str="Failed to query refs for %s repository:" % branch) + if "refs" not in res: + logger.error(f"Invalid branch or tag '{repo[1]}' for repository '{repo[0]}'") + sys.exit(1) + if "tags" in res: + cmd_update = "b=%s;git fetch origin && git checkout tags/$b || (echo \"Error: Could not checkout tag $b\" >&2 && exit 1)" % branch + else: + cmd_update = "b=%s;git reset --hard && git checkout %s && git remote update && (git branch | grep -w $b && (git switch $b && git pull origin $b --rebase) || (git fetch origin && git switch -c $b origin/$b) || (echo \"Error: Could not sync with origin/$b\" >&2 && exit 1))" % (branch, default_branch) + repo_name = repo[0].split('/')[-1].split('.git')[0] repo_path = os.path.join(basepath, repo_name) cmd_clone = "git clone %s %s" % (repo[0], repo_path)