Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force support to 'qmk git-submodule' #19705

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/python/qmk/cli/git/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@

REMOVE_DIRS = [
'lib/ugfx',
'lib/pico-sdk',
'lib/chibios-contrib/ext/mcux-sdk',
'lib/lvgl',
]

IGNORE_DIRS = [
'lib/arm_atsam',
'lib/fnv',
'lib/lib8tion',
'lib/python',
'lib/usbhost',
]


@cli.argument('--check', arg_only=True, action='store_true', help='Check if the submodules are dirty, and display a warning if they are.')
@cli.argument('--sync', arg_only=True, action='store_true', help='Shallow clone any missing submodules.')
@cli.argument('-f', '--force', action='store_true', help='Flag to remove unexpected directories')
@cli.subcommand('Git Submodule actions.')
def git_submodule(cli):
"""Git Submodule actions
Expand All @@ -29,7 +36,15 @@ def git_submodule(cli):
cli.run(['git', 'submodule', 'update', '--depth=50', '--init', name], capture_output=False)
return True

for folder in REMOVE_DIRS:
# can be the default behavior with: qmk config git_submodule.force=True
remove_dirs = REMOVE_DIRS
if cli.config.git_submodule.force:
# Also trash everything that isnt marked as "safe"
for path in normpath('lib').iterdir():
if not any(ignore in path.as_posix() for ignore in IGNORE_DIRS):
remove_dirs.append(path)

for folder in map(normpath, remove_dirs):
if normpath(folder).is_dir():
print(f"Removing '{folder}'")
shutil.rmtree(folder)
Expand Down