From 772611794160f95b094d172daaa1b580328069ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= <frederic.danis@collabora.com>
Date: Wed, 1 Dec 2021 12:30:51 +0100
Subject: [PATCH] common-subtree: Fix branch to use
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The `test/common` repository uses `apertis/v20*` branches, not `main` or
`master`.
`common-subtree.sh` is using the current branch from the working
test repo to infer which remote branch to import: if it's not in the
`apertis/*` form, retrieve the latest branch from the `test/common`
repository.

Signed-off-by: FrĂŠdĂŠric Danis <frederic.danis@collabora.com>
---
 common-subtree.sh | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/common-subtree.sh b/common-subtree.sh
index b757ed6..c99aa60 100755
--- a/common-subtree.sh
+++ b/common-subtree.sh
@@ -8,7 +8,16 @@ usage () {
 }
 
 branch="$(git symbolic-ref --short HEAD)"
-test -z "$branch" && branch="master"
+case "$branch" in
+	apertis/*)
+		;;
+	*)
+        # take the default remote branch if we're not on a apertis/* branch
+		branch=$(git ls-remote --symref git@gitlab.apertis.org:tests/common.git HEAD \
+		         | grep ^ref: \
+		         | sed 's,ref: refs/heads/\(.*\)\s\+HEAD,\1,')
+		;;
+esac
 
 case $1 in
 pull)
-- 
GitLab