From f0f1fac8140be2fd5cfa38193606f17179625072 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Sun, 14 Jan 2024 17:11:03 +0100 Subject: [PATCH] west: Add untracked files and folders to west status output Add untracked files and folder to west status output. This helps to keep the west checkout clean by alerting the user of folders that are no longer tracked by west. This is useful for detecting when a module has been removed, or moved. and is no longer updated by west update. Add the ability to ignore folders and files through a comma separated list in the west config file. Example: west config status.ignore .vscode/,optional/ Fixes: #622 Signed-off-by: Joakim Andersson --- src/west/app/project.py | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/west/app/project.py b/src/west/app/project.py index 9ce105d4..57801446 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -844,6 +844,53 @@ def do_run(self, args, user_args): failed.append(project) self._handle_failed(args, failed) + # List projects not tracked by manifest. + projects = [project.abspath for project in self._cloned_projects(args, only_active=True)] + topdir = Path(self.topdir) + untracked = [] + + self.do_find_untracked(topdir, projects, untracked) + + ignored_config = self.config.get('status.ignore') + ignored = ignored_config.split(',') if ignored_config else [] + # Ignore .west folder in untracked projects + ignored.append('.west/') + for ignore in ignored: + try: + untracked.remove(ignore) + except: + pass + + if len(untracked) > 0: + self.banner('untracked:') + for project in untracked: + self.inf(textwrap.indent(f'{project}', ' ' * 4)) + + def is_manifest_subfolder(self, path, projects): + for project_path in projects: + try: + if Path(project_path).relative_to(Path(path)): + return True + except ValueError: + pass + return False + + def do_find_untracked(self, path, projects, untracked): + obj = os.scandir(path) + + for entry in obj: + if entry.is_dir(): + if entry.path in projects: + continue + if self.is_manifest_subfolder(entry.path, projects): + self.do_find_untracked(entry, projects, untracked) + else: + untracked.append(os.path.relpath(entry.path, Path(self.topdir)) + '/') + if entry.is_file(): + untracked.append(os.path.relpath(entry.path, Path(self.topdir))) + + obj.close() + class Update(_ProjectCommand): def __init__(self):