Skip to content

Commit

Permalink
west: Add untracked files and folders to west status output
Browse files Browse the repository at this point in the history
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: zephyrproject-rtos#622

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
  • Loading branch information
joerchan committed Jan 14, 2024
1 parent 3260b41 commit f0f1fac
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f0f1fac

Please sign in to comment.