sight rewrite of git tools
This commit is contained in:
parent
067667566b
commit
fc8c9a07ec
1 changed files with 19 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
import datalad.api as dl
|
||||
|
||||
GITMODULES_FILE = '.gitmodules'
|
||||
|
||||
|
||||
def move_submodule(repo_path, old_path, new_path):
|
||||
"""
|
||||
|
@ -8,24 +10,31 @@ def move_submodule(repo_path, old_path, new_path):
|
|||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
repo_path: str
|
||||
Path to the repository.
|
||||
old_path: str
|
||||
The old path of the module.
|
||||
new_path: str
|
||||
The new path of the module.
|
||||
"""
|
||||
|
||||
os.rename(repo_path + "/" + old_path, repo_path + "/" + new_path)
|
||||
with open(repo_path + '/.gitmodules', 'r') as fp:
|
||||
lines = fp.readlines()
|
||||
os.rename(os.path.join(repo_path, old_path), os.path.join(repo_path, new_path))
|
||||
# Öffne die.gitmodules-Datei
|
||||
gitmodules_file_path = os.path.join(repo_path, GITMODULES_FILE)
|
||||
with open(gitmodules_file_path, 'r') as file:
|
||||
lines = [line.strip() for line in file]
|
||||
|
||||
# Ersetzen aller Vorkommnisse von old_path durch new_path
|
||||
updated_lines = []
|
||||
for line in lines:
|
||||
if line.startswith('\tpath'):
|
||||
if old_path in line:
|
||||
line = line.replace(old_path, new_path)
|
||||
break
|
||||
if line.startswith('[submodule "projects/tmp"]'):
|
||||
line = line.replace(old_path, new_path)
|
||||
break
|
||||
updated_lines.append(line)
|
||||
|
||||
# Speichen der aktualisierten.gitmodules-Datei
|
||||
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)
|
||||
dl.save(repo_path, message="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