go-git icon indicating copy to clipboard operation
go-git copied to clipboard

server receive-pack: side-band-64k and atomic not supported, breaks native git push over smart HTTP

Open hitzhangjie opened this issue 5 months ago • 1 comments

Summary

When implementing a Git smart HTTP server with plumbing/transport/server, native git push fails if the server advertises common receive-pack capabilities (side-band-64k, atomic) and then handles the push with go-git's receive-pack session.

The request decodes successfully, but ReceivePack returns:

unsupported capability: side-band-64k

The git client then reports:

error: RPC failed; HTTP 500
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

go-git version

github.com/go-git/go-git/v5 v5.19.1

Root cause

rpSession.setSupportedCapabilities only advertises/supports:

  • agent
  • ofs-delta
  • delete-refs
  • report-status

However, smart HTTP servers commonly advertise additional receive-pack capabilities that native git clients will use when present, including:

  • side-band-64k
  • atomic

Upload-pack on the server side already supports sideband capabilities (upSession.setSupportedCapabilities sets Sideband and Sideband64k), but receive-pack does not.

Expected behavior

A go-git HTTP/git server should be able to:

  1. Advertise standard receive-pack capabilities used by native git clients
  2. Accept a native git push over smart HTTP stateless RPC
  3. Return a valid report-status response (including sideband encoding when negotiated)

Actual behavior

  • If the server advertises side-band-64k, native git push fails with unsupported capability: side-band-64k
  • If the server advertises only the capabilities currently supported by rpSession, native git push succeeds and refs are updated correctly

So decode/unpack/ref-update works; the blocker is capability negotiation and response encoding for sideband.

Minimal reproduction

  1. Create an empty bare repo and a local repo with one commit
  2. Run an HTTP test server:
    • GET /repo.git/info/refs?service=git-receive-pack advertises refs with capabilities including side-band-64k and atomic
    • POST /repo.git/git-receive-pack pipes the body to go-git ReferenceUpdateRequest.Decode + server.ReceivePackSession.ReceivePack
  3. Run: git -C <source> push http://127.0.0.1:<port>/repo.git HEAD:refs/heads/main
  4. Observe HTTP 500 and unsupported capability: side-band-64k

If step 2 advertises only report-status, delete-refs, ofs-delta, and agent, the same flow succeeds.

Workaround

Delegate receive-pack to native git:

exec.Command("git", "receive-pack", "--stateless-rpc", ".").Run()

Environment

  • macOS
  • system git client (native push)
  • go-git server path via plumbing/transport/server

Additional context

We are building a Git hosting server and would like to avoid shelling out to the git binary for push. Upload-pack is already handled in pure Go; receive-pack is the remaining blocker.


After I remove side-band-64k and atomic, it still report error when pushing commits or tags. Now I switch to git binary to solve this.

hitzhangjie avatar Jun 23 '26 11:06 hitzhangjie

I've been looking into server-side atomic push support on main.

Since ReferenceStorer doesn't provide transactions, would an implementation that validates all ref updates first and rolls back previously applied updates on failure be acceptable?

The main limitation is that rollback cannot guarantee strict atomicity if another writer modifies the refs concurrently or a rollback operation itself fails.

Would you prefer this approach, or should atomic push support require a transactional storage interface?

ozenyunus35 avatar Oct 11 '26 08:10 ozenyunus35