Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError with LocalGitClient on prior Git cloned repo into MemoryRepo? #1179

Open
dAnjou opened this issue May 17, 2023 · 0 comments
Open

Comments

@dAnjou
Copy link

dAnjou commented May 17, 2023

Hi,

after reporting #1157 I finally got around to having another try, and unfortunately I'm getting a different error now:

Traceback (most recent call last):
  File "/builds/dAnjou/fs-code/src/codefs/_core.py", line 98, in _delegate
    self.mount(mount_point, self.fetch_archive(ref))
                            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/builds/dAnjou/fs-code/src/codefs/gitfs/__init__.py", line [87](https://gitlab.com/dAnjou/fs-code/-/jobs/4301134873#L87), in __call__
    result = self._client.fetch(self._path, self._repo)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/dulwich/client.py", line 1455, in fetch
    refs = r.fetch(
           ^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/dulwich/repo.py", line 417, in fetch
    target.object_store.add_pack_data(count, pack_data, progress)
  File "/usr/local/lib/python3.11/site-packages/dulwich/object_store.py", line 1056, in add_pack_data
    self.add_object(unpacked_object.sha_file())
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/dulwich/pack.py", line 223, in sha_file
    assert self.obj_type_num is not None and self.obj_chunks is not None
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

I noticed the error in one of my CI jobs: https://gitlab.com/dAnjou/fs-code/-/jobs/4301134873, but it can also be reproduced like this:

import subprocess
from dulwich.client import get_transport_and_path
from dulwich.repo import MemoryRepo

# needs pytest for tmp_path fixture

# fails
def test_clone_repo(tmp_path: Path) -> None:
    subprocess.run(["git", "--version"])  # my output: git version 2.40.1
    subprocess.run(["git", "clone", "https://gitlab.com/dAnjou/fs-code.git", str(tmp_path)])
    client, path = get_transport_and_path(str(tmp_path))
    repo = MemoryRepo()
    assert client.fetch(path, repo)

# passes
def test_init_repo(tmp_path: Path) -> None:
    subprocess.run(["git", "--version"])  # my output: git version 2.40.1
    subprocess.run(["git", "init", str(tmp_path)])
    (tmp_path / "file").write_text("lorem ipsum")
    subprocess.run(["git", "add", "file"], cwd=tmp_path)
    subprocess.run(["git", "commit", "-m", "foobar"], cwd=tmp_path)
    client, path = get_transport_and_path(str(tmp_path))
    repo = MemoryRepo()
    assert client.fetch(path, repo)

UPDATE 1: Noticed that it does not happen with a Urllib3HttpGitClient, but it does with a LocalGitClient.

UPDATE 2: I also have a passing test where I create a local repo with Dulwich, the failure seems to happen with a Git cloned repo.

UPDATE 3: Better code sample for reproduction, needs pytest for tmp_path fixture.

UPDATE 4: Yup, needs to be a Git cloned repo, a Git initialized repo does not show the failure.

@dAnjou dAnjou changed the title AssertionError in MemoryRepo? AssertionError with local repo and MemoryRepo? May 18, 2023
@dAnjou dAnjou changed the title AssertionError with local repo and MemoryRepo? AssertionError with LocalGitClient and MemoryRepo? May 18, 2023
@dAnjou dAnjou changed the title AssertionError with LocalGitClient and MemoryRepo? AssertionError with LocalGitClient on prior Git cloned repo into MemoryRepo? May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant