From a1e982aa1eb0a648b23e017b3abbca3bafba43ab Mon Sep 17 00:00:00 2001
From: Luca Weiss <luca@lucaweiss.eu>
Date: Mon, 21 Oct 2024 22:04:50 +0200
Subject: [PATCH] pmb.helpers: Handle workdir version suffix from 2.3.x (MR
 2447)

For the gitlab.com -> gitlab.postmarketos.org migration we needed to
also migrate the workdir in pmb v2 since pmb v3 is not ready yet.

Therefore we need to handle that "7-2.x" workdir version and migrate
correctly when switching to pmbootstrap v3.

See https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2445
---
 pmb/helpers/other.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py
index 10e9e4f7e..888a1efd9 100644
--- a/pmb/helpers/other.py
+++ b/pmb/helpers/other.py
@@ -82,10 +82,16 @@ def migrate_work_folder():
     # Read current version
     context = get_context()
     current = 0
+    suffix: str | None = None
     path = context.config.work / "version"
     if os.path.exists(path):
         with open(path) as f:
-            current = int(f.read().rstrip())
+            # pmb 2.3.x added a suffix due to conflicting work versions
+            # We need to be able to handle that going forward
+            version_parts = f.read().rstrip().split("-")
+            current = int(version_parts[0])
+            if len(version_parts) == 2:
+                suffix = version_parts[1]
 
     # Compare version, print warning or do nothing
     required = pmb.config.work_version
@@ -96,7 +102,8 @@ def migrate_work_folder():
         " (from version " + str(current) + " to " + str(required) + ")!"
     )
 
-    if current == 6:
+    # version 6 and version 7 from 2.3.x branch are equivalent for this and we need to migrate
+    if current == 6 or (current == 7 and suffix == "2.x"):
         # Ask for confirmation
         logging.info("Changelog:")
         logging.info("* Major refactor for pmb 3.0.0")
-- 
GitLab