aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/server/server.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-07-11 14:51:12 +0200
committerSantiago M. Mola <santi@mola.io>2017-07-11 15:07:09 +0200
commit8009cde25dda59ff13a97fabac9abb0b6ef57ef9 (patch)
treebb55566bb72e9c871ac92d1697005badadd5e5d6 /plumbing/transport/server/server.go
parent09cd5ccfd384be79e8c49d0d0bccd22589098809 (diff)
downloadgo-git-8009cde25dda59ff13a97fabac9abb0b6ef57ef9.tar.gz
transport/server: add NewClient
server.NewClient returns a server that acts as a client. This makes it working seamlessly when registering a server directly with `client.InstallProtocol`.
Diffstat (limited to 'plumbing/transport/server/server.go')
-rw-r--r--plumbing/transport/server/server.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/plumbing/transport/server/server.go b/plumbing/transport/server/server.go
index 89fce5f..7b0e7a8 100644
--- a/plumbing/transport/server/server.go
+++ b/plumbing/transport/server/server.go
@@ -26,7 +26,19 @@ type server struct {
// NewServer returns a transport.Transport implementing a git server,
// independent of transport. Each transport must wrap this.
func NewServer(loader Loader) transport.Transport {
- return &server{loader, &handler{}}
+ return &server{
+ loader,
+ &handler{asClient: false},
+ }
+}
+
+// NewClient returns a transport.Transport implementing a client with an
+// embedded server.
+func NewClient(loader Loader) transport.Transport {
+ return &server{
+ loader,
+ &handler{asClient: true},
+ }
}
func (s *server) NewUploadPackSession(ep transport.Endpoint, auth transport.AuthMethod) (transport.UploadPackSession, error) {
@@ -47,24 +59,27 @@ func (s *server) NewReceivePackSession(ep transport.Endpoint, auth transport.Aut
return s.handler.NewReceivePackSession(sto)
}
-type handler struct{}
+type handler struct {
+ asClient bool
+}
func (h *handler) NewUploadPackSession(s storer.Storer) (transport.UploadPackSession, error) {
return &upSession{
- session: session{storer: s},
+ session: session{storer: s, asClient: h.asClient},
}, nil
}
func (h *handler) NewReceivePackSession(s storer.Storer) (transport.ReceivePackSession, error) {
return &rpSession{
- session: session{storer: s},
+ session: session{storer: s, asClient: h.asClient},
cmdStatus: map[plumbing.ReferenceName]error{},
}, nil
}
type session struct {
- storer storer.Storer
- caps *capability.List
+ storer storer.Storer
+ caps *capability.List
+ asClient bool
}
func (s *session) Close() error {
@@ -107,6 +122,10 @@ func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) {
return nil, err
}
+ if s.asClient && len(ar.References) == 0 {
+ return nil, transport.ErrEmptyRemoteRepository
+ }
+
return ar, nil
}