dulwich icon indicating copy to clipboard operation
dulwich copied to clipboard

shallow clone from a google server

Open her01n opened this issue 7 months ago • 2 comments

Shallow clone from googleserver.com url fails with an error.

Run

from dulwich import porcelain
porcelain.clone("https://go.googlesource.com/net", depth = 1)

The function raises an error: unknown command b'acknowledgments\n', it should finish without an error.

Traceback (most recent call last):
  File "/home/heroin/Projekty/veteran/dulwich-source/dulwich/client.py", line 478, in _read_shallow_updates
    cmd, sha = pkt.split(b" ", 1)
    ^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    porcelain.clone("https://go.googlesource.com/net", depth = 1)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/heroin/Projekty/veteran/dulwich-source/dulwich/porcelain.py", line 566, in clone
    return client.clone(
           ~~~~~~~~~~~~^
        path,
        ^^^^^
    ...<9 lines>...
        protocol_version=protocol_version,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/heroin/Projekty/veteran/dulwich-source/dulwich/client.py", line 874, in clone
    result = self.fetch(
        path,
    ...<5 lines>...
        protocol_version=protocol_version,
    )
  File "/home/heroin/Projekty/veteran/dulwich-source/dulwich/client.py", line 981, in fetch
    result = self.fetch_pack(
        path,
    ...<7 lines>...
        protocol_version=protocol_version,
    )
  File "/home/heroin/Projekty/veteran/dulwich-source/dulwich/client.py", line 2737, in fetch_pack
    (new_shallow, new_unshallow) = _read_shallow_updates(
                                   ~~~~~~~~~~~~~~~~~~~~~^
        resp_proto.read_pkt_seq()
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/heroin/Projekty/veteran/dulwich-source/dulwich/client.py", line 480, in _read_shallow_updates
    raise GitProtocolError(f"unknown command {pkt}")
dulwich.errors.GitProtocolError: unknown command b'acknowledgments\n'
>>> 

Version of python is 3.13.3, output of pip list:

Package Version
------- -------
dulwich 0.22.8
pip     25.0.1
urllib3 2.4.0

I have also tested with a recent head ab2c3a09 with the same result.

her01n avatar May 30 '25 08:05 her01n

Thanks, I can reproduce this. FWIW, this looks like a bug in the protocolv2 support (cc @stspdotname ). You can work around this by forcing protocol v1:

from dulwich import porcelain
... porcelain.clone("https://go.googlesource.com/net", depth = 1, protocol_version=1)
...
Counting objects: 34012, done
Finding sources: 100% (34012/34012)
Total 34012 (delta 14751), reused 33426 (delta 14751)
copied 34011 pack entries11/34012
<Repo at 'net'>

jelmer avatar Jun 02 '25 18:06 jelmer

Sorry it took me a while to take a look at this. Finally got around to it.

The key thing was to realize that 'deepen 1' was followed by '0000' in the protocol trace. Not quite obvious at first sight.

stspdotname avatar Jul 08 '25 14:07 stspdotname