40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
|
import os
|
||
|
import subprocess
|
||
|
import configparser
|
||
|
|
||
|
def initialize_repo(gitmodules_path=".gitmodules"):
|
||
|
# Sprawdź, czy istnieje katalog .git, jeśli nie, wykonaj 'git init'
|
||
|
if not os.path.exists(".git"):
|
||
|
subprocess.run(["git", "init"], check=True)
|
||
|
print("Initialized empty Git repository.")
|
||
|
|
||
|
# Wczytaj konfigurację z pliku .gitmodules
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read(gitmodules_path)
|
||
|
|
||
|
# Przejdź przez każdy submoduł i skonfiguruj go
|
||
|
for section in config.sections():
|
||
|
submodule_name = section.split('"')[1]
|
||
|
path = config[section]['path']
|
||
|
url = config[section].get('url')
|
||
|
branch = config[section].get('branch')
|
||
|
|
||
|
if url and branch:
|
||
|
# Dodaj submoduł
|
||
|
subprocess.run(["git", "submodule", "add", "-b", branch, url, path], check=True)
|
||
|
print(f"Added submodule '{submodule_name}' at '{path}' with URL '{url}' and branch '{branch}'.")
|
||
|
|
||
|
# Synchronizuj i inicjalizuj submoduły
|
||
|
subprocess.run(["git", "submodule", "update", "--init", "--recursive", "--force"], check=True)
|
||
|
print("Submodules initialized and updated.")
|
||
|
|
||
|
# Dodaj .gitmodules i zrób commit
|
||
|
subprocess.run(["git", "add", gitmodules_path], check=True)
|
||
|
subprocess.run(["git", "commit", "-m", "Initialize repository with submodules"], check=True)
|
||
|
print("Committed .gitmodules file.")
|
||
|
|
||
|
# Uruchom funkcję inicjalizującą repozytorium i submoduły
|
||
|
initialize_repo()
|
||
|
|
||
|
|