diff mbox series

[4/4] bitbake-setup: print colored diffs

Message ID 20260213-improve-bbsetup-readability-v1-4-41cec3b06992@bootlin.com
State New
Headers show
Series bitbake-setup: Improve readability | expand

Commit Message

Antonin Godard Feb. 13, 2026, 1:50 p.m. UTC
Use the global BBSETUP_COLOR variable to enable color or not in diff
outputs. When passing "auto" to the diff or git diff commands in
subprocess tasks, the color is never shown, which is why we need to
force it using "always" when BBSETUP_COLOR is True.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 bin/bitbake-setup | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index 19db14edb3e..b8acf972e14 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -196,7 +196,9 @@  be preserved in a backup directory.""".format(r_name, r_path))
         status = bb.process.run('git -C {} status --porcelain'.format(r_path))[0]
         if status:
             return True
-        diff = bb.process.run('git -C {} diff {}'.format(r_path, rev))[0]
+        diff = bb.process.run('git -C {} diff --color={} {}'.format(r_path,
+                                                                    "always" if BBSETUP_COLOR else "never",
+                                                                    rev))[0]
         if diff:
             return True
         return False
@@ -722,7 +724,9 @@  def init_config(top_dir, settings, args):
 
 def get_diff(file1, file2):
     try:
-        bb.process.run('diff -uNr {} {}'.format(file1, file2))
+        bb.process.run('diff --color={} -uNr {} {}'.format("always" if BBSETUP_COLOR else "never",
+                                                           file1,
+                                                           file2))
     except bb.process.ExecutionError as e:
         if e.exitcode == 1:
             return e.stdout
@@ -780,7 +784,7 @@  def build_status(top_dir, settings, args, d, update=False):
     new_upstream_config = obtain_config(top_dir, registry, args, source_overrides, d)
 
     write_upstream_config(confdir, new_upstream_config)
-    config_diff = bb.process.run('git -C {} diff'.format(confdir))[0]
+    config_diff = bb.process.run('git -C {} diff --color={}'.format(confdir, "always" if BBSETUP_COLOR else "never"))[0]
 
     if config_diff:
         logger.plain('\nConfiguration in {} has changed:\n{}'.format(setupdir, config_diff))