From fda712139671f19491b618a8d405d28142c8d906 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 16:27:52 +0100
Subject: [PATCH] ci: handle problems with patch generation

---
 .gitlab-ci.yml | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 77b69b8..4709bd6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -85,12 +85,16 @@ Check style:
     - |
       # pre-commit run --all-files
       pre-commit run --color=always --all-files || {
-        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}"
-        test -s "${STYLE_PATCH}" && {
-          printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
+        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}" && {
+          test -s "${STYLE_PATCH}" && {
+            printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
         ${CI_JOB_URL}/artifacts/raw/${STYLE_PATCH}.\n${DEFAULT}"
+          } || {
+            printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+            rm -f "${STYLE_PATCH}"
+          }
         } || {
-          printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+          printf "${RED}Failed to generate a patch file.\n${DEFAULT}"
           rm -f "${STYLE_PATCH}"
         }
         printf "${RED}You can reproduce this check locally with \`pre-commit run --all-files\`.
-- 
GitLab