summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/git
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2023-03-27 19:15:25 +0100
committerGitHub <noreply@github.com>2023-03-27 19:15:25 +0100
commite35bb8ebfad8b8ce40de98e9607fb6dbf8d8fff4 (patch)
treec4f337fb18ddea0d260d397a1499fdf04d9944b8 /lib/python/qmk/cli/git
parent66d56a948043c6acce7ba14ff96b61551f0b8939 (diff)
Add force support to 'qmk git-submodule' (#19705)
Diffstat (limited to 'lib/python/qmk/cli/git')
-rw-r--r--lib/python/qmk/cli/git/submodule.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/python/qmk/cli/git/submodule.py b/lib/python/qmk/cli/git/submodule.py
index 9f354c021e..ef116ea124 100644
--- a/lib/python/qmk/cli/git/submodule.py
+++ b/lib/python/qmk/cli/git/submodule.py
@@ -7,14 +7,21 @@ from qmk import submodules
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
@@ -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)