diff --git a/swh/loader/git/dumb.py b/swh/loader/git/dumb.py --- a/swh/loader/git/dumb.py +++ b/swh/loader/git/dumb.py @@ -41,7 +41,10 @@ """ if not repo_url.startswith("http"): return False - url = urllib.parse.urljoin(repo_url, "info/refs?service=git-upload-pack/") + url = urllib.parse.urljoin( + repo_url.rstrip("/") + "/", "info/refs?service=git-upload-pack/" + ) + logger.debug("Fetching %s", url) response = requests.get(url, headers=HEADERS) content_type = response.headers.get("Content-Type") return ( @@ -113,7 +116,8 @@ return map(self._get_git_object, self.objects[object_type]) def _http_get(self, path: str) -> SpooledTemporaryFile: - url = urllib.parse.urljoin(self.repo_url, path) + url = urllib.parse.urljoin(self.repo_url.rstrip("/") + "/", path) + logger.debug("Fetching %s", url) response = self._session.get(url, headers=HEADERS) buffer = SpooledTemporaryFile(max_size=100 * 1024 * 1024) for chunk in response.iter_content(chunk_size=10 * 1024 * 1024): diff --git a/swh/loader/git/tests/test_loader.py b/swh/loader/git/tests/test_loader.py --- a/swh/loader/git/tests/test_loader.py +++ b/swh/loader/git/tests/test_loader.py @@ -158,18 +158,22 @@ if with_pack_files: # create a bare clone of that repository in another folder, # all objects will be contained in one or two pack files in that case - bare_repo_path = os.path.join(tmp_path, archive_name + "_bare") + http_root_dir = tmp_path + repo_name = archive_name + "_bare" + bare_repo_path = os.path.join(http_root_dir, repo_name) subprocess.run( ["git", "clone", "--bare", base_repo_url, bare_repo_path], check=True, ) else: # otherwise serve objects from the bare repository located in # the .git folder of the base repository - bare_repo_path = os.path.join(destination_path, ".git") + http_root_dir = destination_path + repo_name = ".git" + bare_repo_path = os.path.join(http_root_dir, repo_name) # spawn local HTTP server that will serve the bare repository files hostname = "localhost" - handler = partial(SimpleHTTPRequestHandler, directory=bare_repo_path) + handler = partial(SimpleHTTPRequestHandler, directory=http_root_dir) httpd = HTTPServer((hostname, 0), handler, bind_and_activate=True) def serve_forever(httpd): @@ -213,7 +217,7 @@ return super().load() # bare repository with dumb protocol only URL - self.repo_url = f"http://{httpd.server_name}:{httpd.server_port}" + self.repo_url = f"http://{httpd.server_name}:{httpd.server_port}/{repo_name}" self.loader = DumbGitLoaderTest(swh_storage, self.repo_url) self.repo = repo