From ecad536c9e179f48529d388d6e3866f973fe0b04 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Sun, 30 Mar 2025 18:04:05 +0000 Subject: [PATCH] better moving of submodules --- corrlib/git_tools.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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)