diff mbox series

[5/9] bitbake-setup: report local modifications blocking an update

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

Commit Message

AdrianF March 22, 2026, 7:34 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

When unpack_update() detects uncommitted changes in a layer repository
it raises an UnpackError, which previously propagated as an unhandled
exception with an opaque traceback.

Catch the UnpackError in _checkout_git_remote and re-raise it as a
plain Exception with a message that:
- names the affected source and its path
- tells the user to commit, stash or discard the changes
- includes the original error detail for diagnostics

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 bin/bitbake-setup | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Richard Purdie March 23, 2026, 2:26 p.m. UTC | #1
On Sun, 2026-03-22 at 20:34 +0100, Adrian Freihofer via lists.openembedded.org wrote:
> From: Adrian Freihofer <adrian.freihofer@siemens.com>
> 
> When unpack_update() detects uncommitted changes in a layer repository
> it raises an UnpackError, which previously propagated as an unhandled
> exception with an opaque traceback.
> 
> Catch the UnpackError in _checkout_git_remote and re-raise it as a
> plain Exception with a message that:
> - names the affected source and its path
> - tells the user to commit, stash or discard the changes
> - includes the original error detail for diagnostics
> 
> Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
> ---
>  bin/bitbake-setup | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/bin/bitbake-setup b/bin/bitbake-setup
> index e8d520687..6d24f8fcc 100755
> --- a/bin/bitbake-setup
> +++ b/bin/bitbake-setup
> @@ -182,7 +182,14 @@ def checkout_layers(layers, confdir, layerdir, d):
>              else:
>                  src_uri = f"{fetchuri};protocol={prot};rev={rev};nobranch=1;destsuffix={repodir}"
>              fetcher = bb.fetch.Fetch([src_uri], d)
> -            do_fetch(fetcher, layerdir)
> +            repodir_path = os.path.join(layerdir, repodir)
> +            try:
> +                do_fetch(fetcher, layerdir)
> +            except bb.fetch2.UnpackError as e:
> +                raise Exception(
> +                    "Cannot update source '{}' in {} because it has local modifications.\n"
> +                    "Please commit, stash or discard your changes and re-run the update.\n"
> +                    "Details: {}".format(r_name, repodir_path, e)) from None
>              urldata = fetcher.ud[src_uri]
>              revision = urldata.revision
>              layers_fixed_revisions[r_name]['git-remote']['rev'] = revision

The pythonic thing to do here is probably to create a new exception for
local change in the fetcher itself, subclassing UnpackError with the
sting you're using as the error string?

Cheers,

Richard
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index e8d520687..6d24f8fcc 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -182,7 +182,14 @@  def checkout_layers(layers, confdir, layerdir, d):
             else:
                 src_uri = f"{fetchuri};protocol={prot};rev={rev};nobranch=1;destsuffix={repodir}"
             fetcher = bb.fetch.Fetch([src_uri], d)
-            do_fetch(fetcher, layerdir)
+            repodir_path = os.path.join(layerdir, repodir)
+            try:
+                do_fetch(fetcher, layerdir)
+            except bb.fetch2.UnpackError as e:
+                raise Exception(
+                    "Cannot update source '{}' in {} because it has local modifications.\n"
+                    "Please commit, stash or discard your changes and re-run the update.\n"
+                    "Details: {}".format(r_name, repodir_path, e)) from None
             urldata = fetcher.ud[src_uri]
             revision = urldata.revision
             layers_fixed_revisions[r_name]['git-remote']['rev'] = revision