GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — plumbing: transport, replace transport API with new design by aymanbagabas · Pull Request #1972 · go-git/go-git Conversation
|
| Old | New |
|---|---|
Connection interface |
Session interface (Capabilities, GetRemoteRefs, Fetch, Push, Close) |
Session interface |
Transport interface (Handshake) |
Endpoint struct |
*url.URL (standard library) |
NewEndpoint(string) |
ParseURL(string) → *url.URL |
Get(scheme) via registry |
client.New() + client.Handshake(ctx, req) |
Auth transport.AuthMethod |
Transport-specific auth via client.WithSSHAuth(...), client.WithHTTPAuth(...), etc. |
ProxyOptions in core |
Moved to sub-transport config options |
backend/git + backend/http |
Single backend package with Serve, ServeHTTP, RequestFromProto |
| # | Description | PR |
|---|---|---|
| 1 | Replace plumbing/transport core |
aymanbagabas#5 |
| 2 | Replace internal/transport/test suites |
aymanbagabas#6 |
| 3 | Replace plumbing/transport/ssh |
aymanbagabas#7 |
| 4 | Replace plumbing/transport/http |
aymanbagabas#8 |
| 5 | Replace plumbing/transport/git |
aymanbagabas#9 |
| 6 | Replace plumbing/transport/file |
aymanbagabas#10 |
| 7 | Add plumbing/client |
aymanbagabas#11 |
| 8 | Rewire callers to new API | aymanbagabas#12 |
| 9 | Rewire server/backends | aymanbagabas#13 |
| 10 | Update examples | aymanbagabas#14 |
| 11 | Fix build, lint, race, and test errors | aymanbagabas#15 |
| 12 | Unify backend/git and backend/http into single backend package |
aymanbagabas#16 |
| 13 | Follow-up comments and feedback | aymanbagabas#17 |
New packages:
plumbing/client — scheme-based transport resolution, replacing plumbing/transport/registry.gobackend — unified backend serving Git over any transport (Serve, ServeHTTP, RequestFromProto)Core (plumbing/transport/):
Replaced the old Endpoint/Connection/Session/Registry design with a cleaner Transport/Session/Conn hierarchy. Endpoints are now standard *url.URL values. The old global transport registry is gone — scheme resolution moved to plumbing/client.
// Old ep, _ := transport.NewEndpoint("https://github.com/org/repo") t := transport.Get(ep.Scheme()) conn, _ := t.NewSession(ep, ...) _ = conn.Handshake(ctx, ...) // New u := transport.ParseURL("https://github.com/org/repo") c := client.New() sess, _ := c.Handshake(ctx, &transport.Request{URL: u, ...})
New files: doc.go, errors.go, pack_session.go, pack_stream.go, protocol.go, request.go, session_stream.go, url.go. Deleted: registry.go, mocks.go, pack.go.
Sub-transports:
Each sub-transport now implements Transport.Handshake directly, returning a Session with transport-specific capabilities. Dedicated handshake layers separate protocol negotiation from transport I/O. SSH globals (DefaultSSHConfig, DefaultAuthBuilder) were removed in favor of per-instance Options.
// SSH: per-instance options instead of globals opts := &ssh.Options{UserSettings: mySettings, ClientConfig: myConfig} t := ssh.NewTransport(opts) // HTTP: dedicated auth, TLS, and redirect handling t := http.NewTransport(http.Options{TLS: &tls.Config{InsecureSkipVerify: true}})
Callers:
All option structs (CloneOptions, PullOptions, FetchOptions, PushOptions, etc.) now use a single ClientOptions []client.Option field instead of separate Auth, InsecureSkipTLS, CABundle, and ProxyOptions fields. This lets callers compose transport-specific configuration without the library needing a shared AuthMethod interface.
// Old opts := &git.CloneOptions{ URL: "https://github.com/org/repo", Auth: &http.BasicAuth{Username: "user", Password: "pass"}, } // New opts := &git.CloneOptions{ URL: "https://github.com/org/repo", ClientOptions: []client.Option{ client.WithHTTPAuth(&http.BasicAuth{Username: "user", Password: "pass"}), }, }
Backends:
Merged backend/git and backend/http into a single backend package. Backend.Serve is the single entrypoint for all transports — callers pass their own reader/writer and decide the wire format. A new unified backend.Request type replaces the scattered packp.GitProtoRequest, HTTP headers, and SSH session command parsing.
b := backend.New(loader) // TCP/SSH: call Serve directly _ = b.Serve(ctx, conn, conn, &backend.Request{URL: u, Service: "git-upload-pack"}) // HTTP: use ServeHTTP which implements http.Handler http.Handle("/", b) // TCP helper: convert git daemon protocol request req := backend.RequestFromProto(gitProtoReq)
Examples:
All examples updated to use ClientOptions with transport-specific option helpers.
// SSH auth opts := &git.CloneOptions{ ClientOptions: []client.Option{client.WithSSHAuth(publicKeys)}, } // HTTP auth opts := &git.CloneOptions{ ClientOptions: []client.Option{ client.WithHTTPAuth(&http.BasicAuth{Username: "user", Password: "pass"}), }, } // Custom HTTP client opts := &git.CloneOptions{ ClientOptions: []client.Option{client.WithHTTPClient(customClient)}, }
Cleanup (PR 11):
NewConn generic wrapper; each transport implements transport.Conn directlyPush/Fetch, not Close() — errors return at the operation sitesshConn.Close() — removed stdin.Close() that raced with in-flight ctxWriter goroutinesOptionsgo build, go vet, go test -race ./..., golangci-lint run all pass
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Replace the alpha plumbing/transport API with the new x/transport API. Copy all core files from x/transport/ to plumbing/transport/ with import path rewrites. Delete old files that have no equivalent in the new API (registry.go, mocks.go, pack.go). See rfcs/0002-replace-plumbing-transport.md for design rationale.
Replace the old upload_pack.go and receive_pack.go test suites in internal/transport/test/ with the new versions from x/transport/test/. These new suites test against the new plumbing/transport API.
Replace the old plumbing/transport/ssh package with the new version from x/transport/ssh. This includes the new auth, handshake, knownhosts, and sshagent implementations.
Replace the old plumbing/transport/http package with the new version from x/transport/http. This includes new auth, handshake, dumb HTTP, TLS, redirect, and proxy implementations.
Replace the old plumbing/transport/git package with the new version from x/transport/git. Includes new handshake implementation.
Replace the old plumbing/transport/file package with the new version from x/transport/file. Includes new handshake implementation.
Add plumbing/client from x/client. This package provides scheme-based transport resolution, replacing the old registry.go functionality.
Replace old transport API usage in remote.go, repository.go, submodule.go, and options.go with the new plumbing/transport and plumbing/client APIs. Key changes: - Replace Auth, InsecureSkipTLS, CABundle, ProxyOptions fields with ClientOptions []client.Option on all option structs - Replace newClient() to use client.New() + transport.ParseURL() - Collapse Transport.NewSession + Session.Handshake into client.Handshake - Pass storer to Session.Fetch/Push (new signature) - Replace transport.NewEndpoint with transport.ParseURL (*url.URL)
Update server and backend packages for the new plumbing/transport API: - Replace transport.Service type with plain string - Replace transport.NewEndpoint with transport.ParseURL (*url.URL) - Replace svc.Name()/service.Name() with transport.ServiceName() - Update Loader.Load signature from *Endpoint to *url.URL
Update all examples that use authentication or custom HTTP clients to use the new client.Option pattern instead of the old Auth field and transport.Register.
Fix all remaining build, test, and lint errors after the transport API migration so the full stack compiles, passes go vet, and all tests pass. Highlights: - Remove NewConn helper; each transport now implements transport.Conn directly (sshConn, gitConn, fileConn) - Surface remote stderr at Push/Fetch via Stderr() io.Reader interface instead of at Close() time — the idiomatic Go pattern for subprocess error reporting - Replace UploadPackOptions/ReceivePackOptions with UploadPackRequest/ ReceivePackRequest in backend packages - Fix missing closing paren and stale variable references in remote.go - Update worktree.go to use ClientOptions instead of old fields - Consolidate duplicate internal/transport/test imports across all sub-transport test files - Refactor duplicated test code into table-driven tests and shared setup helpers (file, git, ssh) - Fix TestHostKeyCallbackHelper_NilFallback to account for /etc/ssh/ssh_known_hosts - Fix gci import ordering across all modified files Verified: go build, go vet, go test ./..., and example tests all pass.
The go.mod requires v6 but test files still imported v5.
Merge backend/git and backend/http into a single backend package with a unified API: - Backend.Serve(ctx, r, w, *Request) — core dispatch for all transports - Backend.ServeConn(ctx, rwc, *Request) — convenience for full-duplex connections (TCP, SSH, pipes) - Backend.ServeHTTP(w, r) — HTTP adapter (smart + dumb protocols) - RequestFromProto(*packp.GitProtoRequest) — helper for TCP git daemon The shared logic (loader resolution, service dispatch, UploadPack/ ReceivePack invocation) lives in Serve. HTTP-specific concerns (routing, gzip, content-type, dumb file serving) stay in ServeHTTP. Error handling is the caller's responsibility — Serve returns errors instead of writing them to the wire. Delete backend/git/ and backend/http/ subpackages. Update internal/server/http to import backend directly.
Co-authored-by: Paulo Gomes <[email protected]> Co-authored-by: Ayman Bagabas <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
0a68212 to
c9bc20c
Compare
|
A summary of the changes needs to be added to #910 or directly pushed into v5-v6 migration guide. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This adds a regression on http redirection (e.g. cloning without the .git suffix). Let's fix that and add a test to block future regressions. Apart from that we can go ahead and merge this.
Other improvements will be done as follow-up PRs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Pushed a fix
I opened https://github.com/aymanbagabas/go-git-docs/pull/1 for this 🙂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@aymanbagabas thanks for working on this. 🙇
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.