|
9 | 9 | import sys |
10 | 10 | from typing import TYPE_CHECKING |
11 | 11 |
|
12 | | -import git |
13 | 12 | import pytest |
14 | 13 |
|
15 | 14 | from gitingest.clone import clone_repo |
@@ -104,19 +103,18 @@ async def test_check_repo_exists( |
104 | 103 | expected: bool, |
105 | 104 | mocker: MockerFixture, |
106 | 105 | ) -> None: |
107 | | - """Verify that ``check_repo_exists`` interprets git ls-remote results correctly.""" |
108 | | - mock_git = mocker.patch("git.Git") |
109 | | - mock_git_instance = mock_git.return_value |
| 106 | + """Verify that ``check_repo_exists`` works by using _resolve_ref_to_sha.""" |
| 107 | + mock_resolve = mocker.patch("gitingest.utils.git_utils._resolve_ref_to_sha") |
110 | 108 |
|
111 | 109 | if git_command_succeeds: |
112 | | - mock_git_instance.ls_remote.return_value = "abc123\trefs/heads/main\n" |
| 110 | + mock_resolve.return_value = "abc123def456" # Mock SHA |
113 | 111 | else: |
114 | | - mock_git_instance.ls_remote.side_effect = git.GitCommandError("ls-remote", 128) |
| 112 | + mock_resolve.side_effect = ValueError("Repository not found") |
115 | 113 |
|
116 | 114 | result = await check_repo_exists(DEMO_URL) |
117 | 115 |
|
118 | 116 | assert result is expected |
119 | | - mock_git_instance.ls_remote.assert_called_once_with(DEMO_URL, "--exit-code") |
| 117 | + mock_resolve.assert_called_once_with(DEMO_URL, "HEAD", token=None) |
120 | 118 |
|
121 | 119 |
|
122 | 120 | @pytest.mark.asyncio |
@@ -213,22 +211,13 @@ async def test_check_repo_exists_with_auth_token(mocker: MockerFixture) -> None: |
213 | 211 |
|
214 | 212 | Given a GitHub URL and a token: |
215 | 213 | When ``check_repo_exists`` is called, |
216 | | - Then it should add the token to the URL and call git ls-remote. |
| 214 | + Then it should pass the token to _resolve_ref_to_sha. |
217 | 215 | """ |
218 | | - mock_git = mocker.patch("git.Git") |
219 | | - mock_git_instance = mock_git.return_value |
220 | | - mock_git_instance.ls_remote.return_value = "abc123\trefs/heads/main\n" |
221 | | - |
222 | | - # Mock the _add_token_to_url function |
223 | | - mock_add_token = mocker.patch("gitingest.utils.git_utils._add_token_to_url") |
224 | | - mock_add_token.return_value = "https://x-oauth-basic:token123@github.com/test/repo" |
| 216 | + mock_resolve = mocker.patch("gitingest.utils.git_utils._resolve_ref_to_sha") |
| 217 | + mock_resolve.return_value = "abc123def456" # Mock SHA |
225 | 218 |
|
226 | 219 | test_token = "token123" # noqa: S105 |
227 | 220 | result = await check_repo_exists("https://github.com/test/repo", token=test_token) |
228 | 221 |
|
229 | 222 | assert result is True |
230 | | - mock_add_token.assert_called_once_with("https://github.com/test/repo", "token123") |
231 | | - mock_git_instance.ls_remote.assert_called_once_with( |
232 | | - "https://x-oauth-basic:token123@github.com/test/repo", |
233 | | - "--exit-code", |
234 | | - ) |
| 223 | + mock_resolve.assert_called_once_with("https://github.com/test/repo", "HEAD", token=test_token) |
0 commit comments