Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/tmt_web/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +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 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}")
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down