aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorDavid Cuadrado <krawek@gmail.com>2021-03-26 11:02:47 -0500
committerGitHub <noreply@github.com>2021-03-26 17:02:47 +0100
commit1f328388192915476c68e5e0c8c1c818fd50fc6b (patch)
tree7df158c886cb51c10f0d4ba1814bd198d07d255e /plumbing
parentbf3471db54b0255ab5b159005069f37528a151b7 (diff)
downloadgo-git-1f328388192915476c68e5e0c8c1c818fd50fc6b.tar.gz
transport: ssh, fix cloning large repositories (#272)
* Fix cloning large repositories Ignore the error on close when the connection is already closed Fixes #70 * Compatibility for go 1.13 Because it's required by the pipeline * Add test for allowing to close a command when the client is already closed This test is for issue #70 * Add debug information for broken test
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/transport/ssh/common.go9
-rw-r--r--plumbing/transport/ssh/common_test.go21
2 files changed, 29 insertions, 1 deletions
diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go
index c05ded9..46e7913 100644
--- a/plumbing/transport/ssh/common.go
+++ b/plumbing/transport/ssh/common.go
@@ -6,6 +6,7 @@ import (
"fmt"
"reflect"
"strconv"
+ "strings"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/internal/common"
@@ -90,8 +91,14 @@ func (c *command) Close() error {
//XXX: If did read the full packfile, then the session might be already
// closed.
_ = c.Session.Close()
+ err := c.client.Close()
- return c.client.Close()
+ //XXX: in go1.16+ we can use errors.Is(err, net.ErrClosed)
+ if err != nil && strings.HasSuffix(err.Error(), "use of closed network connection") {
+ return nil
+ }
+
+ return err
}
// connect connects to the SSH server, unless a AuthMethod was set with
diff --git a/plumbing/transport/ssh/common_test.go b/plumbing/transport/ssh/common_test.go
index 87c1148..e04a9c5 100644
--- a/plumbing/transport/ssh/common_test.go
+++ b/plumbing/transport/ssh/common_test.go
@@ -7,6 +7,7 @@ import (
"github.com/kevinburke/ssh_config"
"golang.org/x/crypto/ssh"
+ stdssh "golang.org/x/crypto/ssh"
. "gopkg.in/check.v1"
)
@@ -93,6 +94,26 @@ func (s *SuiteCommon) TestDefaultSSHConfigWildcard(c *C) {
c.Assert(cmd.getHostWithPort(), Equals, "github.com:22")
}
+func (s *SuiteCommon) TestIssue70(c *C) {
+ uploadPack := &UploadPackSuite{}
+ uploadPack.SetUpSuite(c)
+
+ config := &ssh.ClientConfig{
+ HostKeyCallback: stdssh.InsecureIgnoreHostKey(),
+ }
+ r := &runner{
+ config: config,
+ }
+
+ cmd, err := r.Command("command", uploadPack.newEndpoint(c, "endpoint"), uploadPack.EmptyAuth)
+ c.Assert(err, IsNil)
+
+ c.Assert(cmd.(*command).client.Close(), IsNil)
+
+ err = cmd.Close()
+ c.Assert(err, IsNil)
+}
+
type mockSSHConfig struct {
Values map[string]map[string]string
}