backend: shallow clone (--depth 1) fails over stateless HTTP — missing shallow line in phase 2 response

Aperta
#2,011 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
git, go

Direzione di ricerca

Parti dalla gestione di Smart HTTP di backend.Backend per git-upload-pack con StatelessRPC abilitato e traccia il modo in cui vengono analizzate e serializzate le due fasi POST di un clone shallow. Riproduci con git clone --depth 1 verso il server protocol-v1, quindi verifica che la risposta della fase 2 ripeta shallow prima di NAK e che il clone riesca.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

stale

Problem

When serving a git repository via `backend.Backend` (Smart HTTP, `StatelessRPC: true`), a `git clone --depth 1` fails with:

```
fatal: git fetch-pack: expected shallow list
```

This was discovered while running a self-hosted git marketplace server for Claude Code plugin marketplaces. Claude Code always clones marketplaces with `--depth 1 --recurse-submodules --shallow-submodules`, so this failure blocks every marketplace add/refresh.

Root Cause

The shallow clone protocol over stateless HTTP requires two POST requests:

Phase 1 — client sends `want + deepen 1`:

Server → shallow <hash>   ✅ go-git sends this correctly
Server → flush

Phase 2 — client sends `want + done`:

Server → shallow <hash>   ❌ go-git omits this
Server → NAK
Server → <pack data>

The client expects `shallow ` to appear again before `NAK` in the phase 2 response. go-git sends `NAK` without it, causing the client to error with `expected shallow list`.

Evidence (captured packet trace)

Without workaround — go-git phase 2 response:

fetch-pack< shallow 7aabc998...   ← phase 1 OK
fetch-pack> done
fetch-pack< NAK                   ← phase 2 missing shallow line!
fatal: git fetch-pack: expected shallow list

With workaround — intercepting the two phases manually:

fetch-pack< shallow 7aabc998...   ← phase 1 (intercepted)
fetch-pack> done
fetch-pack< shallow 7aabc998...   ← phase 2 (injected)
fetch-pack< NAK
✓ clone succeeds

Workaround

We implemented a middleware that intercepts `git-upload-pack` POST requests:

  1. Phase 1 (`want + deepen`): handle entirely ourselves, return `shallow + flush` without involving go-git
  2. Phase 2 (`want + done`): pass to go-git, then inject the `shallow ` pkt-line into the response before the NAK

This works but is fragile and shouldn't be necessary.

Environment

  • go-git: `v6.0.0-alpha.2`
  • Client: `git/2.53.0-Linux` (system git called by Claude Code)
  • Client clone flags: `git clone --depth 1 --recurse-submodules --shallow-submodules`
  • Protocol: v1

Note: I'm not deeply familiar with the git wire protocol internals — this issue was written with help from Claude Code, which also helped diagnose the problem by capturing and analysing the git packet traces.

Lingua principale
Go
Stelle
7.9k
Fork
1.1k
Merge medio
4g 19h
PR unite (30g)
34

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di go-git/go-git

Tutte le issue di go-git/go-git

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.