From 211ec2aefd77d757922ef8701c4062c06608554e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 23 Mar 2024 19:01:26 +0100 Subject: [PATCH] support main branch for app to test as git repository --- lib/common.sh | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 1c7e378..1821ebd 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -322,7 +322,7 @@ function fetch_package_to_test() { # If the url is on a specific branch, extract the branch if echo "$path_to_package_to_test" | grep -Eq "https?:\/\/.*\/tree\/" then - gitbranch="-b ${path_to_package_to_test##*/tree/}" + gitbranch="${path_to_package_to_test##*/tree/}" path_to_package_to_test="${path_to_package_to_test%%/tree/*}" fi @@ -331,28 +331,25 @@ function fetch_package_to_test() { package_path="$TEST_CONTEXT/app_folder" # If the package is in a git repository - if echo "$path_to_package_to_test" | grep -Eq "https?:\/\/" - then + if echo "$path_to_package_to_test" | grep -Eq "https?:\/\/"; then # Force the branch master if no branch is specified. - if [ -z "$gitbranch" ] - then - if git ls-remote --quiet --exit-code $path_to_package_to_test master >/dev/null - then - gitbranch="-b master" - else - if git ls-remote --quiet --exit-code $path_to_package_to_test stable >/dev/null - then - gitbranch="-b stable" - else - log_critical "Unable to find a default branch to test (master or stable)" + if [ -z "$gitbranch" ]; then + branches=(master main stable) + for branch in "${branches[@]}"; do + if git ls-remote --quiet --exit-code "$path_to_package_to_test" "$branch" >/dev/null; then + gitbranch="$branch" + break fi + done + if [ -z "$gitbranch" ]; then + log_critical "Unable to find a default branch to test (master or stable)" fi fi - log_info " on branch ${gitbranch##-b }" + log_info " on branch ${gitbranch}" # Clone the repository - git clone --quiet $path_to_package_to_test $gitbranch "$package_path" + git clone --quiet $path_to_package_to_test -b "$gitbranch" "$package_path" if [[ ! -e "$package_path" ]] then