Initializes a new git repository in the given path. If folder does not exist, it creates it. If the folder already exists, it deletes the content of the folder.
(
path_to_repo: Union[str, os.PathLike],
module_name: Optional[str] = None,
render_id: Optional[str] = None,
initial_files: Optional[dict[str, str]] = None,
)
| 61 | |
| 62 | |
| 63 | def init_git_repo( |
| 64 | path_to_repo: Union[str, os.PathLike], |
| 65 | module_name: Optional[str] = None, |
| 66 | render_id: Optional[str] = None, |
| 67 | initial_files: Optional[dict[str, str]] = None, |
| 68 | ) -> Repo: |
| 69 | """ |
| 70 | Initializes a new git repository in the given path. |
| 71 | If folder does not exist, it creates it. |
| 72 | If the folder already exists, it deletes the content of the folder. |
| 73 | """ |
| 74 | if os.path.isdir(path_to_repo): |
| 75 | file_utils.delete_files_and_subfolders(path_to_repo) |
| 76 | else: |
| 77 | os.makedirs(path_to_repo) |
| 78 | |
| 79 | repo = Repo.init(path_to_repo) |
| 80 | _ensure_git_config(repo) |
| 81 | |
| 82 | if initial_files: |
| 83 | file_utils.store_response_files(path_to_repo, initial_files, []) |
| 84 | repo.git.add(".") |
| 85 | |
| 86 | repo.git.commit( |
| 87 | "--allow-empty", "-m", _get_full_commit_message(INITIAL_COMMIT_MESSAGE, module_name, None, render_id) |
| 88 | ) |
| 89 | |
| 90 | return repo |
| 91 | |
| 92 | |
| 93 | def clone_repo( |