diff --git a/corrlib/git_tools.py b/corrlib/git_tools.py index b66191b..6569be0 100644 --- a/corrlib/git_tools.py +++ b/corrlib/git_tools.py @@ -1,5 +1,6 @@ import os import datalad.api as dl +import git GITMODULES_FILE = '.gitmodules' @@ -19,7 +20,10 @@ def move_submodule(repo_path, old_path, new_path): """ os.rename(os.path.join(repo_path, old_path), os.path.join(repo_path, new_path)) + gitmodules_file_path = os.path.join(repo_path, GITMODULES_FILE) + + # update paths in .gitmodules with open(gitmodules_file_path, 'r') as file: lines = [line.strip() for line in file] @@ -32,6 +36,8 @@ def move_submodule(repo_path, old_path, new_path): with open(gitmodules_file_path, 'w') as file: file.write("\n".join(updated_lines)) - with open(repo_path + '/.gitmodules', 'w') as fp: - fp.writelines(lines) + # stage .gitmodules in git + repo = git.Repo(repo_path) + repo.git.add('.gitmodules') + # save new state of the dataset dl.save(repo_path, message=f"Move module from {old_path} to {new_path}", dataset=repo_path)