aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/common.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-25 09:25:49 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-25 09:25:49 +0100
commit9e34f68d980de57631c588aaa910c9ea95ed7c2e (patch)
treeb1bd9f867b757ca46ada2f349d122723dde3529c /plumbing/transport/ssh/common.go
parent8966c042795509ed17730e50d352ad69901c3da8 (diff)
downloadgo-git-9e34f68d980de57631c588aaa910c9ea95ed7c2e.tar.gz
plumbing/transport: add common tests and fixes. (#136)
* plumbing/transport: add common tests and fixes. * add common test suite for different transport implementations. * fix different behaviour on error handling for ssh and http. fixes issue #123. * support detecting unexisting repositories with SSH + GitHub/Bitbucket (apparently, there is no standard for all SSH servers). * remove ssh.NewClient (only DefaultClient makes sense at the moment). * make ssh.Client and http.Client private. * utils/ioutil: utilities to work with io interfaces. * * transport: test actual objects fetched, not just packfile size. * * fix doc typo. * * improve UploadPackRequest.IsEmpty
Diffstat (limited to 'plumbing/transport/ssh/common.go')
-rw-r--r--plumbing/transport/ssh/common.go52
1 files changed, 35 insertions, 17 deletions
diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go
index 6f0f3d4..c327c41 100644
--- a/plumbing/transport/ssh/common.go
+++ b/plumbing/transport/ssh/common.go
@@ -11,32 +11,22 @@ import (
"golang.org/x/crypto/ssh"
)
-// New errors introduced by this package.
var (
- ErrAdvertistedReferencesAlreadyCalled = errors.New("cannot call AdvertisedReference twice")
- ErrAlreadyConnected = errors.New("ssh session already created")
- ErrAuthRequired = errors.New("cannot connect: auth required")
- ErrNotConnected = errors.New("not connected")
- ErrUploadPackAnswerFormat = errors.New("git-upload-pack bad answer format")
- ErrUnsupportedVCS = errors.New("only git is supported")
- ErrUnsupportedRepo = errors.New("only github.com is supported")
+ errAlreadyConnected = errors.New("ssh session already created")
)
-type Client struct{}
+type client struct{}
-var DefaultClient = NewClient()
+// DefaultClient is the default SSH client.
+var DefaultClient = &client{}
-func NewClient() transport.Client {
- return &Client{}
-}
-
-func (c *Client) NewFetchPackSession(ep transport.Endpoint) (
+func (c *client) NewFetchPackSession(ep transport.Endpoint) (
transport.FetchPackSession, error) {
return newFetchPackSession(ep)
}
-func (c *Client) NewSendPackSession(ep transport.Endpoint) (
+func (c *client) NewSendPackSession(ep transport.Endpoint) (
transport.SendPackSession, error) {
return newSendPackSession(ep)
@@ -49,6 +39,7 @@ type session struct {
session *ssh.Session
stdin io.WriteCloser
stdout io.Reader
+ stderr io.Reader
sessionDone chan error
auth AuthMethod
}
@@ -70,6 +61,11 @@ func (s *session) Close() error {
}
s.connected = false
+
+ //XXX: If did read the full packfile, then the session might be already
+ // closed.
+ _ = s.session.Close()
+
return s.client.Close()
}
@@ -79,7 +75,7 @@ func (s *session) Close() error {
// environment var.
func (s *session) connect() error {
if s.connected {
- return ErrAlreadyConnected
+ return errAlreadyConnected
}
if err := s.setAuthFromEndpoint(); err != nil {
@@ -138,6 +134,11 @@ func (s *session) openSSHSession() error {
return fmt.Errorf("cannot pipe remote stdout: %s", err)
}
+ s.stderr, err = s.session.StderrPipe()
+ if err != nil {
+ return fmt.Errorf("cannot pipe remote stderr: %s", err)
+ }
+
return nil
}
@@ -149,3 +150,20 @@ func (s *session) runCommand(cmd string) chan error {
return done
}
+
+const (
+ githubRepoNotFoundErr = "ERROR: Repository not found."
+ bitbucketRepoNotFoundErr = "conq: repository does not exist."
+)
+
+func isRepoNotFoundError(s string) bool {
+ if strings.HasPrefix(s, githubRepoNotFoundErr) {
+ return true
+ }
+
+ if strings.HasPrefix(s, bitbucketRepoNotFoundErr) {
+ return true
+ }
+
+ return false
+}