at master 1.8 kB view raw
1import shutil 2from pathlib import Path 3 4from milc import cli 5 6from qmk import submodules 7 8REMOVE_DIRS = [ 9 'lib/ugfx', 10 'lib/chibios-contrib/ext/mcux-sdk', 11] 12 13IGNORE_DIRS = [ 14 'lib/arm_atsam', 15 'lib/fnv', 16 'lib/lib8tion', 17 'lib/python', 18 'lib/usbhost', 19] 20 21 22@cli.argument('--check', arg_only=True, action='store_true', help='Check if the submodules are dirty, and display a warning if they are.') 23@cli.argument('--sync', arg_only=True, action='store_true', help='Shallow clone any missing submodules.') 24@cli.argument('-f', '--force', action='store_true', help='Flag to remove unexpected directories') 25@cli.subcommand('Git Submodule actions.') 26def git_submodule(cli): 27 """Git Submodule actions 28 """ 29 if cli.args.check: 30 return all(item['status'] for item in submodules.status().values()) 31 32 if cli.args.sync: 33 cli.run(['git', 'submodule', 'sync', '--recursive']) 34 for name, item in submodules.status().items(): 35 if item['status'] is None: 36 cli.run(['git', 'submodule', 'update', '--depth=50', '--init', name], capture_output=False) 37 return True 38 39 # can be the default behavior with: qmk config git_submodule.force=True 40 remove_dirs = REMOVE_DIRS 41 if cli.config.git_submodule.force: 42 # Also trash everything that isnt marked as "safe" 43 for path in Path('lib').iterdir(): 44 if not any(ignore in path.as_posix() for ignore in IGNORE_DIRS): 45 remove_dirs.append(path) 46 47 for folder in map(Path, remove_dirs): 48 if folder.is_dir(): 49 print(f"Removing '{folder}'") 50 shutil.rmtree(folder) 51 52 cli.run(['git', 'submodule', 'sync', '--recursive'], capture_output=False) 53 cli.run(['git', 'submodule', 'update', '--init', '--recursive', '--progress'], capture_output=False)