Skip to content

Commit

Permalink
Hash clone url to ensure clone dir uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Havlin committed Oct 24, 2024
1 parent 7b567ab commit d4bacb7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/tmt_web/utils/git_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import os
import hashlib
from shutil import rmtree

from tmt import Logger
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d4bacb7

Please sign in to comment.