From a53ec10cf28b4e500b5095eec33086cac1a6d839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Fri, 6 Mar 2020 11:34:45 -0800 Subject: [PATCH] west diff: only print output for projects with nonempty diffs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The output is kind of cluttered when many projects are available. Let's silence output for projects with no diff when not in verbose mode. Signed-off-by: Martí Bolívar --- src/west/app/project.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/west/app/project.py b/src/west/app/project.py index 8e1cdb0..c07fa1e 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -556,16 +556,30 @@ class Diff(_ProjectCommand): self._setup_logging(args) failed = [] + no_diff = 0 + # We may need to force git to use colors if the user wants them, + # which it won't do ordinarily since stdout is not a terminal. + color = ['--color=always'] if log.use_color() else [] + for project in self._cloned_projects(args): - log.banner(f'diff for {project.name_and_path}:') # Use paths that are relative to the base directory to make it # easier to see where the changes are - try: - project.git(['diff', f'--src-prefix={project.path}/', - f'--dst-prefix={project.path}/']) - except subprocess.CalledProcessError: + cp = project.git(['diff', f'--src-prefix={project.path}/', + f'--dst-prefix={project.path}/', + '--exit-code'] + color, + capture_stdout=True, capture_stderr=True, + check=False) + if cp.returncode == 0: + no_diff += 1 + if cp.returncode == 1 or log.VERBOSE > log.VERBOSE_NONE: + log.banner(f'diff for {project.name_and_path}:') + log.inf(cp.stdout.decode('utf-8')) + elif cp.returncode: failed.append(project) - self._handle_failed(args, failed) + if failed: + self._handle_failed(args, failed) + elif log.VERBOSE <= log.VERBOSE_NONE: + log.inf(f"Empty diff in {no_diff} projects.") class Status(_ProjectCommand): def __init__(self):