diff mbox series

[v2,01/10] fetch2: add LocalModificationsError for uncommitted changes blocking update

Message ID 20260325071342.47272-2-adrian.freihofer@siemens.com
State New
Headers show
Series bitbake-setup: improvements, VSCode workspace generation | expand

Commit Message

AdrianF March 25, 2026, 6:51 a.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

When unpack_update() detects uncommitted changes in a layer repository
it now raises LocalModificationsError, a new subclass of UnpackError,
instead of a plain UnpackError. The new exception:
- takes (repodir, url, git_output) as arguments
- builds the full user-facing message in its __init__, combining the
  git status output with guidance to commit, stash or discard changes
- keeps the is-a relationship with UnpackError so existing callers are
  not broken

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 lib/bb/fetch2/__init__.py | 8 ++++++++
 lib/bb/fetch2/git.py      | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index 909ae9814..b39cfcd45 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -96,6 +96,14 @@  class UnpackError(BBFetchException):
         BBFetchException.__init__(self, msg)
         self.args = (message, url)
 
+class LocalModificationsError(UnpackError):
+    """Exception raised when a checkout cannot be updated due to local modifications"""
+    def __init__(self, repodir, url, git_output):
+        message = ("Repository at %s has uncommitted changes, unable to update:\n%s\n"
+                   "Please commit, stash or discard your changes and re-run the update." % (repodir, git_output))
+        UnpackError.__init__(self, message, url)
+        self.args = (repodir, url, git_output)
+
 class NoMethodError(BBFetchException):
     """Exception raised when there is no method to obtain a supplied url or set of urls"""
     def __init__(self, url):
diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 84fecdad0..c398f7e9d 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -730,7 +730,7 @@  class Git(FetchMethod):
 
             output = runfetchcmd("%s status --untracked-files=no --porcelain" % (ud.basecmd), d, workdir=destdir)
             if output:
-                raise bb.fetch2.UnpackError("Repository at %s has uncommitted changes, unable to update:\n%s" % (destdir, output), ud.url)
+                raise bb.fetch2.LocalModificationsError(destdir, ud.url, output)
 
             # Set up remote for the download location if it doesn't exist
             try: