Skip to content

Commit

Permalink
west diff: only print output for projects with nonempty diffs
Browse files Browse the repository at this point in the history
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 <marti.bolivar@nordicsemi.no>
  • Loading branch information
mbolivar-nordic committed Mar 11, 2020
1 parent 3416c4c commit c8aecab
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,30 @@ def do_run(self, args, ignored):
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):
Expand Down

0 comments on commit c8aecab

Please sign in to comment.