Skip to content

Commit

Permalink
fixed submodule issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjeffreyz committed May 27, 2022
1 parent dd4fee4 commit a2166f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources
Submodule resources updated 1 files
+1 −1 README.md
23 changes: 18 additions & 5 deletions src/modules/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,37 @@ 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
while i < len(lines):
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')

0 comments on commit a2166f8

Please sign in to comment.