diff --git a/src/tmt_web/utils/git_handler.py b/src/tmt_web/utils/git_handler.py index a78a852..60b0cd2 100644 --- a/src/tmt_web/utils/git_handler.py +++ b/src/tmt_web/utils/git_handler.py @@ -1,5 +1,6 @@ import contextlib import os +import hashlib from shutil import rmtree from tmt import Logger @@ -73,14 +74,15 @@ def clone_repository(url: str, logger: Logger, ref: str | None = None) -> None: def get_path_to_repository(url: str) -> Path: """ - Returns the path to the cloned repository from the given URL. + Returns the path to the cloned repository from the given URL. The repository url is hashed to + avoid repository name collisions. :param url: URL to the repository :return: Path to the cloned repository """ - repo_name = url.rstrip("/").rsplit("/", 1)[-1] + clone_dir_name = hashlib.md5(url.encode()).hexdigest() root_dir = Path(__file__).resolve().parents[2] # going up from tmt_web/utils/git_handler.py - return root_dir / os.getenv("CLONE_DIR_PATH", "./.repos/") / repo_name + return root_dir / os.getenv("CLONE_DIR_PATH", "./.repos/") / clone_dir_name def check_if_repository_exists(url: str) -> bool: