diff --git a/renku/ui/service/cache/models/project.py b/renku/ui/service/cache/models/project.py index 070cadb3a8..55be10ac63 100644 --- a/renku/ui/service/cache/models/project.py +++ b/renku/ui/service/cache/models/project.py @@ -29,6 +29,7 @@ MAX_CONCURRENT_PROJECT_REQUESTS = 10 LOCK_TIMEOUT = 15 +NO_BRANCH_FOLDER = "__default_branch__" class Project(Model): @@ -57,7 +58,10 @@ class Project(Model): @property def abs_path(self) -> Path: """Full path of cached project.""" - return CACHE_PROJECTS_PATH / self.user_id / self.owner / self.slug + branch = self.branch + if not self.branch: + branch = NO_BRANCH_FOLDER + return CACHE_PROJECTS_PATH / self.user_id / self.owner / self.slug / branch def read_lock(self, timeout: Optional[float] = None): """Shared read lock on the project.""" diff --git a/renku/ui/service/utils/__init__.py b/renku/ui/service/utils/__init__.py index 7260efdd81..e9756068f4 100644 --- a/renku/ui/service/utils/__init__.py +++ b/renku/ui/service/utils/__init__.py @@ -17,6 +17,7 @@ """Renku service utility functions.""" from renku.core.util.git import push_changes +from renku.ui.service.cache.models.project import NO_BRANCH_FOLDER from renku.ui.service.config import CACHE_PROJECTS_PATH, CACHE_UPLOADS_PATH @@ -26,7 +27,13 @@ def make_project_path(user, project): valid_project = project and "owner" in project and "name" in project and "project_id" in project if valid_user and valid_project: - return CACHE_PROJECTS_PATH / user["user_id"] / project["owner"] / project["slug"] + return ( + CACHE_PROJECTS_PATH + / user["user_id"] + / project["owner"] + / project["slug"] + / project.get("branch", NO_BRANCH_FOLDER) + ) def make_file_path(user, cached_file): diff --git a/tests/service/controllers/test_templates_create_project.py b/tests/service/controllers/test_templates_create_project.py index d2ab69c80c..e38320ee33 100644 --- a/tests/service/controllers/test_templates_create_project.py +++ b/tests/service/controllers/test_templates_create_project.py @@ -39,7 +39,7 @@ def test_template_create_project_ctrl(ctrl_init, svc_client_templates_creation, # Check ctrl_mock. assert ctrl_mock.call_count == 1 - assert response.json["result"]["slug"] == ctrl_mock.call_args[0][0].name + assert response.json["result"]["slug"] == ctrl_mock.call_args[0][0].parent.name # Ctrl state. expected_context = { @@ -165,6 +165,8 @@ def test_template_create_project_with_custom_cli_ctrl( ctrl_init, svc_cache_dir, svc_client_templates_creation, mocker, monkeypatch ): """Test template create project controller.""" + from renku.ui.service.cache.models.project import NO_BRANCH_FOLDER + monkeypatch.setenv("RENKU_PROJECT_DEFAULT_CLI_VERSION", "9.9.9rc9") from renku.ui.service.controllers.templates_create_project import TemplatesCreateProjectCtrl @@ -182,7 +184,11 @@ def test_template_create_project_with_custom_cli_ctrl( cache_dir, _ = svc_cache_dir project_path = ( - cache_dir / user_data["user_id"] / response.json["result"]["namespace"] / response.json["result"]["slug"] + cache_dir + / user_data["user_id"] + / response.json["result"]["namespace"] + / response.json["result"]["slug"] + / NO_BRANCH_FOLDER ) with open(project_path / "Dockerfile") as f: diff --git a/tests/service/views/test_templates_views.py b/tests/service/views/test_templates_views.py index eeff9937de..3e26292fc5 100644 --- a/tests/service/views/test_templates_views.py +++ b/tests/service/views/test_templates_views.py @@ -124,6 +124,7 @@ def test_read_manifest_from_wrong_template(svc_client_with_templates, template_u @retry_failed def test_create_project_from_template(svc_client_templates_creation, with_injection): """Check creating project from a valid template.""" + from renku.ui.service.cache.models.project import NO_BRANCH_FOLDER from renku.ui.service.serializers.headers import RenkuHeaders from renku.ui.service.utils import CACHE_PROJECTS_PATH @@ -142,7 +143,9 @@ def test_create_project_from_template(svc_client_templates_creation, with_inject # NOTE: assert correct git user is set on new project user_data = RenkuHeaders.decode_user(headers["Renku-User"]) - project_path = CACHE_PROJECTS_PATH / user_data["user_id"] / payload["project_namespace"] / stripped_name + project_path = ( + CACHE_PROJECTS_PATH / user_data["user_id"] / payload["project_namespace"] / stripped_name / NO_BRANCH_FOLDER + ) reader = Repository(project_path).get_configuration() assert reader.get_value("user", "email") == user_data["email"] assert reader.get_value("user", "name") == user_data["name"]