-
-
Notifications
You must be signed in to change notification settings - Fork 954
Repo.clone_from localhost #1493
-
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,
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?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
This looks like the server should support the dumb http protocol which requires a little more than hosting a git repository via http. I assume the repository is available on the same machine so it's fine to specify a local filesystem path as url.
To see if it works, I suggest to use the git command-line rather than GitPython for less convoluted error reporting.
Beta Was this translation helpful? Give feedback.
All reactions
-
I assume the repository is available on the same machine so it's fine to specify a local filesystem path as url
This worked,
git.repo.Repo.clone_from("/private/var/folders/2z/142033n17rbfy969s6h4hymw0000gn/T/pytest-of-michele/pytest-26/server0/test_git_repo", path)
though it kind of fails to test what really will happens in the real case (the function to test works on a gitlab repository - using the ssh protocol)
I went to the git page to read about this dumb protocol, but I am not sure how to implement it...my server class and instance look like this,
class Server(Thread): def __init__(self, directory): super().__init__() self.event = Event() handler = partial(SimpleHTTPRequestHandler, directory=directory) self.httpd = HTTPServer(("", 0), handler) self.url = f"http://localhost:{self.httpd.server_port}" self.httpd.timeout = 0.1 self.httpd.handle_timeout = lambda: None def run(self): with self.httpd: while not self.event.is_set(): self.httpd.handle_request()
@pytest.fixture(scope="module") def server(server_tmp_path): s = Server(server_tmp_path) s.start() try: yield s finally: s.event.set() s.join()
Beta Was this translation helpful? Give feedback.