Skip to content

Commit 91efb42

Browse files
authored
Merge pull request #368 from bssrikanth/tagcheckout_tests
Add branch/tag handling for tests
2 parents 59ae97d + 0e8c8e2 commit 91efb42

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

avocado-setup.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,25 @@ def get_repo(repo, basepath):
229229
if not isinstance(repo, tuple):
230230
repo = (repo, '')
231231

232+
cmd_default_branch = "git ls-remote --symref %s HEAD | grep '^ref:' | awk '{print $2}' | cut -d'/' -f3" % repo[0]
233+
status, default_branch = helper.runcmd(cmd_default_branch, err_str="Failed to find default branch for %s repository:" % repo[0])
234+
if status != 0:
235+
logger.warning(f"Failed to find default branch for {repo[0]} repository, going ahead assuming master branch as default branch")
236+
default_branch = "master"
232237
if repo[1] == '':
233-
branch = "master"
238+
branch = default_branch
234239
else:
235240
branch = repo[1]
236-
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
241+
cmd_istag = "git ls-remote --refs %s %s" % (repo[0], branch)
242+
status, res = helper.runcmd(cmd_istag, err_str="Failed to query refs for %s repository:" % branch)
243+
if "refs" not in res:
244+
logger.error(f"Invalid branch or tag '{repo[1]}' for repository '{repo[0]}'")
245+
sys.exit(1)
246+
if "tags" in res:
247+
cmd_update = "b=%s;git fetch origin && git checkout tags/$b || (echo \"Error: Could not checkout tag $b\" >&2 && exit 1)" % branch
248+
else:
249+
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)
250+
237251
repo_name = repo[0].split('/')[-1].split('.git')[0]
238252
repo_path = os.path.join(basepath, repo_name)
239253
cmd_clone = "git clone %s %s" % (repo[0], repo_path)

0 commit comments

Comments
 (0)