From 7908196d194b4536b60ccf13914f5722ab97cda4 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Fri, 9 Jun 2017 12:13:53 +0200 Subject: ensure receive-pack session is closed on push. * at low level, ReceivePack must close its stream to the server to signal it has finished. * remote.go: Close() must be called on session. --- plumbing/transport/internal/common/common.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'plumbing/transport/internal/common/common.go') diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index f67ae29..7001d05 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -263,6 +263,10 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS return nil, err } + if err := s.Stdin.Close(); err != nil { + return nil, err + } + if !req.Capabilities.Supports(capability.ReportStatus) { // If we have neither report-status or sideband, we can only // check return value error. @@ -302,7 +306,7 @@ func (s *session) finish() error { func (s *session) Close() error { if err := s.finish(); err != nil { _ = s.Command.Close() - return nil + return err } return s.Command.Close() -- cgit From 20637689e489758b36d46e2409e20eb4fa703e73 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 12 Jun 2017 11:26:27 +0200 Subject: plumbing/transport: detect git protocol "no such repository" error --- plumbing/transport/internal/common/common.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'plumbing/transport/internal/common/common.go') diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 7001d05..41be776 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -337,6 +337,7 @@ var ( bitbucketRepoNotFoundErr = "conq: repository does not exist." localRepoNotFoundErr = "does not appear to be a git repository" gitProtocolNotFoundErr = "ERR \n Repository not found." + gitProtocolNoSuchErr = "ERR no such repository" ) func isRepoNotFoundError(s string) bool { @@ -356,6 +357,10 @@ func isRepoNotFoundError(s string) bool { return true } + if strings.HasPrefix(s, gitProtocolNoSuchErr) { + return true + } + return false } -- cgit From 9ebf0e651465fc304405d0253f837c1b5e929c24 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 12 Jun 2017 13:51:01 +0200 Subject: plumbing/transport: detect "access denied error" "ERR access denied or repository not exported:" is now detected as transport.ErrRepositoryNotFound, since that's what git-daemon returns when --informative-errors is not used. --- plumbing/transport/internal/common/common.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'plumbing/transport/internal/common/common.go') diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 41be776..d947d28 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -333,11 +333,12 @@ func (s *session) checkNotFoundError() error { } var ( - githubRepoNotFoundErr = "ERROR: Repository not found." - bitbucketRepoNotFoundErr = "conq: repository does not exist." - localRepoNotFoundErr = "does not appear to be a git repository" - gitProtocolNotFoundErr = "ERR \n Repository not found." - gitProtocolNoSuchErr = "ERR no such repository" + githubRepoNotFoundErr = "ERROR: Repository not found." + bitbucketRepoNotFoundErr = "conq: repository does not exist." + localRepoNotFoundErr = "does not appear to be a git repository" + gitProtocolNotFoundErr = "ERR \n Repository not found." + gitProtocolNoSuchErr = "ERR no such repository" + gitProtocolAccessDeniedErr = "ERR access denied" ) func isRepoNotFoundError(s string) bool { @@ -361,6 +362,10 @@ func isRepoNotFoundError(s string) bool { return true } + if strings.HasPrefix(s, gitProtocolAccessDeniedErr) { + return true + } + return false } -- cgit From cbbd2a9ad8ee990c79bd847b0df2823e2449ea4e Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Tue, 13 Jun 2017 14:23:15 +0200 Subject: transport/internal: remove Wait function, use Close directly --- plumbing/transport/internal/common/common.go | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'plumbing/transport/internal/common/common.go') diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index d947d28..c1e1518 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -59,14 +59,8 @@ type Command interface { // Start starts the specified command. It does not wait for it to // complete. Start() error - // Wait waits for the command to exit. It must have been started by - // Start. The returned error is nil if the command runs, has no - // problems copying stdin, stdout, and stderr, and exits with a zero - // exit status. - Wait() error // Close closes the command and releases any resources used by it. It - // can be called to forcibly finish the command without calling to Wait - // or to release resources after calling Wait. + // will block until the command exits. Close() error } @@ -178,6 +172,7 @@ func (s *session) handleAdvRefDecodeError(err error) error { // If repository is not found, we get empty stdout and server writes an // error to stderr. if err == packp.ErrEmptyInput { + s.finished = true if err := s.checkNotFoundError(); err != nil { return err } @@ -246,9 +241,7 @@ func (s *session) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackRes return nil, err } - wc := &waitCloser{s.Command} - rc := ioutil.NewReadCloser(r, wc) - + rc := ioutil.NewReadCloser(r, s.Command) return DecodeUploadPackResponse(rc, req) } @@ -270,7 +263,7 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS if !req.Capabilities.Supports(capability.ReportStatus) { // If we have neither report-status or sideband, we can only // check return value error. - return nil, s.Command.Wait() + return nil, s.Command.Close() } report := packp.NewReportStatus() @@ -282,7 +275,7 @@ func (s *session) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.ReportS return report, err } - return report, s.Command.Wait() + return report, s.Command.Close() } func (s *session) finish() error { @@ -417,12 +410,3 @@ func DecodeUploadPackResponse(r io.ReadCloser, req *packp.UploadPackRequest) ( return res, nil } - -type waitCloser struct { - Command Command -} - -// Close waits until the command exits and returns error, if any. -func (c *waitCloser) Close() error { - return c.Command.Wait() -} -- cgit