better moving of submodules
This commit is contained in:
parent
fef6d95f97
commit
ecad536c9e
1 changed files with 8 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import datalad.api as dl
|
import datalad.api as dl
|
||||||
|
import git
|
||||||
|
|
||||||
GITMODULES_FILE = '.gitmodules'
|
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))
|
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)
|
gitmodules_file_path = os.path.join(repo_path, GITMODULES_FILE)
|
||||||
|
|
||||||
|
# update paths in .gitmodules
|
||||||
with open(gitmodules_file_path, 'r') as file:
|
with open(gitmodules_file_path, 'r') as file:
|
||||||
lines = [line.strip() for line in 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:
|
with open(gitmodules_file_path, 'w') as file:
|
||||||
file.write("\n".join(updated_lines))
|
file.write("\n".join(updated_lines))
|
||||||
|
|
||||||
with open(repo_path + '/.gitmodules', 'w') as fp:
|
# stage .gitmodules in git
|
||||||
fp.writelines(lines)
|
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)
|
dl.save(repo_path, message=f"Move module from {old_path} to {new_path}", dataset=repo_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue