feat(terminal): use project name for in-container cwd and clone directory

This commit is contained in:
Developer
2026-06-17 13:26:16 +00:00
parent 93da9b42a2
commit 3e59a257dc
9 changed files with 196 additions and 146 deletions
+18 -3
View File
@@ -2,17 +2,27 @@
import logging
import os
import re
import subprocess
from pathlib import Path
logger = logging.getLogger(__name__)
def _slugify_directory_name(name: str) -> str:
"""Return a filesystem-safe, lowercase directory slug."""
slug = name.lower().strip()
slug = re.sub(r"[^a-z0-9_-]+", "-", slug)
slug = re.sub(r"-+", "-", slug).strip("-")
return slug or "project"
def clone_repository(
remote_url: str,
ssh_key_path: str | None,
instance_dir: str,
branch: str = "main",
project_name: str | None = None,
) -> str:
"""Clone a git repository into the instance directory.
@@ -21,11 +31,14 @@ def clone_repository(
ssh_key_path: Path to SSH private key for authentication (optional)
instance_dir: Path to instance directory
branch: Branch to clone (default: main)
project_name: Optional project name used as the clone directory name
instead of the generic ``repo-clone``.
Returns:
Path to the cloned repository
"""
clone_path = Path(instance_dir) / "repo-clone"
clone_name = _slugify_directory_name(project_name) if project_name else "repo-clone"
clone_path = Path(instance_dir) / clone_name
clone_path.mkdir(parents=True, exist_ok=True)
env = os.environ.copy()
@@ -84,13 +97,15 @@ def check_dirty_state(clone_path: str) -> tuple[bool, list[str]]:
return is_dirty, changed_files
def remove_clone_directory(instance_dir: str) -> None:
def remove_clone_directory(instance_dir: str, project_name: str | None = None) -> None:
"""Remove the cloned repository from the instance directory.
Args:
instance_dir: Path to instance directory
project_name: Optional project name used as the clone directory name.
"""
clone_path = Path(instance_dir) / "repo-clone"
clone_name = _slugify_directory_name(project_name) if project_name else "repo-clone"
clone_path = Path(instance_dir) / clone_name
if clone_path.exists():
import shutil
shutil.rmtree(clone_path)