From a2166f8c32741f8e51d6c2f48672d5a5154a579a Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Fri, 27 May 2022 00:40:48 -0700 Subject: [PATCH] fixed submodule issues --- resources | 2 +- src/modules/bot.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/resources b/resources index 0298e080..f1f80cf0 160000 --- a/resources +++ b/resources @@ -1 +1 @@ -Subproject commit 0298e080b8d34701e8075cc5f7d2d346380fc39b +Subproject commit f1f80cf02bdb95331dc5a9f962dbcd1f5e40d15f diff --git a/src/modules/bot.py b/src/modules/bot.py index 13254638..7ad8b62b 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -211,9 +211,10 @@ def load_commands(self, file): return False @staticmethod - def _update_submodules(): + def _update_submodules(force=False): print('\n[~] Retrieving latest submodules:') repo = git.Repo.init() + changed = False with open('.gitmodules', 'r') as file: lines = file.readlines() i = 0 @@ -221,14 +222,26 @@ def _update_submodules(): if lines[i].startswith('[') and i < len(lines) - 2: path = lines[i + 1].split('=')[1].strip() url = lines[i + 2].split('=')[1].strip() - try: + try: # First time loading submodule repo.git.clone(url, path) + changed = True print(f" - Initialized submodule '{path}'") except git.exc.GitCommandError: sub_repo = git.Repo(path) - sub_repo.git.fetch('origin', 'main') - sub_repo.git.reset('--hard', 'FETCH_HEAD') - print(f" - Updated submodule '{path}'") + if force: + sub_repo.git.fetch('origin', 'main') + sub_repo.git.reset('--hard', 'FETCH_HEAD') + changed = True + print(f" - Force-updated submodule '{path}'") + else: + try: + sub_repo.git.pull('origin', 'main') + changed = True + print(f" - Updated submodule '{path}'") + except git.exc.GitCommandError: + print(f" ! Uncommitted changes in submodule '{path}'") i += 3 else: i += 1 + if not changed: + print(' ~ All submodules are already up to date')