From 78895d0893e2356f16bd92fd50cd014ee6c09e01 Mon Sep 17 00:00:00 2001 From: Miroslav Vadkerti Date: Tue, 8 Jul 2025 17:53:19 +0200 Subject: [PATCH 1/2] Fix handling of '.' as tree_path in get_tree function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When tree_path is '.', the current code constructs invalid paths like '/path/to/repo./' which causes "Invalid directory path" errors. This fix adds special handling for '.' (current directory) to avoid path modification while still handling .git suffix removal properly. Fixes #19 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/tmt_web/service.py | 6 +++++- tests/unit/test_service.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/tmt_web/service.py b/src/tmt_web/service.py index 0ab0a77..a3139f6 100644 --- a/src/tmt_web/service.py +++ b/src/tmt_web/service.py @@ -42,7 +42,11 @@ def get_tree(url: str, name: str, ref: str | None, tree_path: str | None) -> tmt except Exception as exc: raise GeneralError(f"Failed to clone repository: {exc}") from exc - if tree_path is not None: + if tree_path == ".": + # Handle current directory case - no path modification needed + if path.suffix == ".git": + path = path.with_suffix("") + elif tree_path is not None: tree_path += "/" # If path is set, construct a path to the tmt Tree if path.suffix == ".git": diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index 24437f5..5b226d5 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -100,6 +100,38 @@ def test_get_tree_with_git_suffix(mocker): mock_path.with_suffix.assert_called_once_with("") +def test_get_tree_with_dot_path(mocker): + """Test get_tree with '.' as tree_path (current directory).""" + mock_path = mocker.Mock() + mock_path.suffix = "" + mock_path.with_suffix.return_value = mock_path + mock_path.as_posix.return_value = "/path/to/repo" + mocker.patch("tmt_web.utils.git_handler.get_git_repository", return_value=mock_path) + mocker.patch("tmt.base.Tree") + mocker.patch("tmt.plugins.explore") + + get_tree("url", "test", None, ".") + # Should not call as_posix() when tree_path is "." + mock_path.as_posix.assert_not_called() + + +def test_get_tree_with_dot_path_and_git_suffix(mocker): + """Test get_tree with '.' as tree_path and .git suffix.""" + mock_path = mocker.Mock() + mock_path.suffix = ".git" + mock_path.with_suffix.return_value = mock_path + mock_path.as_posix.return_value = "/path/to/repo" + mocker.patch("tmt_web.utils.git_handler.get_git_repository", return_value=mock_path) + mocker.patch("tmt.base.Tree") + mocker.patch("tmt.plugins.explore") + + get_tree("url", "test", None, ".") + # Should still strip .git suffix when tree_path is "." + mock_path.with_suffix.assert_called_once_with("") + # Should not call as_posix() when tree_path is "." + mock_path.as_posix.assert_not_called() + + def test_format_data_unsupported_format(mocker, logger): """Test format_data with unsupported format.""" test_data = TestData(name="test") From ae3e0b8ac7d2941aea0f49ef42018d0951304f55 Mon Sep 17 00:00:00 2001 From: Miroslav Vadkerti Date: Mon, 3 Nov 2025 14:27:42 +0100 Subject: [PATCH 2/2] Resolve review comment Signed-off-by: Miroslav Vadkerti --- src/tmt_web/service.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/tmt_web/service.py b/src/tmt_web/service.py index a3139f6..d9cb4da 100644 --- a/src/tmt_web/service.py +++ b/src/tmt_web/service.py @@ -42,15 +42,13 @@ def get_tree(url: str, name: str, ref: str | None, tree_path: str | None) -> tmt except Exception as exc: raise GeneralError(f"Failed to clone repository: {exc}") from exc - if tree_path == ".": - # Handle current directory case - no path modification needed - if path.suffix == ".git": - path = path.with_suffix("") - elif tree_path is not None: + # Remove .git suffix if present + if path.suffix == ".git": + path = path.with_suffix("") + + # If path is set, construct a path to the tmt Tree + if tree_path is not None and tree_path != ".": tree_path += "/" - # If path is set, construct a path to the tmt Tree - if path.suffix == ".git": - path = path.with_suffix("") path = Path(path.as_posix() + tree_path) logger.debug(f"Looking for tree in {path}")