From 2bdc110bbdb83689245e0857a15ebd4d39d1884f Mon Sep 17 00:00:00 2001
From: Thomas Schaffter <thomas.schaffter@gmail.com>
Date: Mon, 18 Mar 2024 16:50:10 +0000
Subject: [PATCH] comment

---
 .github/workflows/sonar-scan.yml | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml
index fcdbdf9a83..f115a29815 100644
--- a/.github/workflows/sonar-scan.yml
+++ b/.github/workflows/sonar-scan.yml
@@ -27,8 +27,16 @@ jobs:
           # against.
           fetch-depth: 0
 
-      - name: Switch from the detached HEAD of the merge commit to a new branch
+      - name: Check if the HEAD is detached
         # Buildx does not work on a detached HEAD
+        id: is_head_detached
+        run: |
+          # return exit code 1 if the head is detached
+          git symbolic-ref -q HEAD > /dev/null 2>&1
+          echo "detached=$?" >> "$GITHUB_OUTPUT"
+
+      - name: Switch from the detached HEAD of the merge commit to a new branch
+        if: ${{ steps.is_head_detached.outputs.detached }}
         run: git switch -c new-branch
 
       - name: Derive appropriate SHAs for base and head for `nx affected` commands