From e39e36e5f6bc6852fd102ab5f9d9cec79ae752e4 Mon Sep 17 00:00:00 2001
From: Fabio Manganiello <fabio@manganiello.tech>
Date: Mon, 2 Sep 2024 02:31:11 +0200
Subject: [PATCH] [CI/CD] A more resilient `github-mirror` script.

- Fail immediately if no branches are checked out.

- Rebase only if we're pushing on master (don't bother for feature
  branches).

- Do a push force to Github.
---
 .drone/github-mirror.sh | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/.drone/github-mirror.sh b/.drone/github-mirror.sh
index 20832d4b5..4727946c8 100755
--- a/.drone/github-mirror.sh
+++ b/.drone/github-mirror.sh
@@ -6,9 +6,18 @@
 ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
 
 # Clone the repository
+branch=$(git rev-parse --abbrev-ref HEAD)
+if [ -z "${branch}" ]; then
+  echo "No branch checked out"
+  exit 1
+fi
+
 git remote add github git@github.com:/blacklight/platypush.git
-git pull --rebase github "$(git branch | head -1 | awk '{print $2}')" || echo "No such branch on Github"
+
+if (( "$branch" == "master" )); then
+  git pull --rebase github "${branch}" || echo "No such branch on Github"
+fi
 
 # Push the changes to the GitHub mirror
-git push --all -v github
+git push -f --all -v github
 git push --tags -v github