Skip to content

Repo.clone_from localhost #1492

@HealthyPear

Description

@HealthyPear

Within a pytest suite I have created a Server(Thread) class and a server_tmp_path factory in order to simulate the download of a git repository in my project (actually I might need to download only a specific file, but I have to download the whole repo first, am I right?).

I create the test repo like this,

@pytest.fixture(scope="module")
def test_git_repo(server_tmp_path):
    """Initialize a dummy git repository"""
    import git

    repo_dir = server_tmp_path / "test_git_repo"
    file_name = "test_file.txt"
    file_name_2 = "test_file_2.txt"

    r = git.Repo.init(repo_dir)
    Path(repo_dir / file_name).touch()
    Path(repo_dir / file_name_2).touch()
    r.index.add([file_name])
    r.index.add([file_name_2])
    r.index.commit("initial commit")

    return repo_dir

and then I define the test function as test_download_git_repo(server, test_git_repo, tmp_path) so then from inside I can retrieve the URL of the test repo (e.g. http://localhost:51848/test_git_repo/) and see that the stuff is there,

image

When I cd the directory I can see that it corresponds to an initialized git repository with 1 main branch and the initial commit.

So I am a bit baffled that when I try to do the following,

path = tmp_path / test_git_repo.name
git.repo.Repo.clone_from(f"{server.url}/{test_git_repo.name}", path)

I get the following Traceback,

127.0.0.1 - - [13/Sep/2022 18:07:34] code 404, message File not found
127.0.0.1 - - [13/Sep/2022 18:07:34] "GET /test_git_repo/info/refs?service=git-upload-pack HTTP/1.1" 404 -
*** git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git clone -v http://localhost:51848/test_git_repo /private/var/folders/2z/142033n17rbfy969s6h4hymw0000gn/T/pytest-of-michele/pytest-27/test_download_git_repo0/test_git_repo
  stderr: 'Cloning into '/private/var/folders/2z/142033n17rbfy969s6h4hymw0000gn/T/pytest-of-michele/pytest-27/test_download_git_repo0/test_git_repo'...
fatal: repository 'http://localhost:51848/test_git_repo/' not found

Any idea what could be the problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions