From 2b4fdd78027384f973649140b91c556e680d7917 Mon Sep 17 00:00:00 2001 From: David Cuadrado Date: Thu, 25 Mar 2021 12:19:21 -0500 Subject: [PATCH 1/4] Fix cloning large repositories Ignore the error on close when the connection is already closed Fixes #70 --- plumbing/transport/ssh/common.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go index c05ded986..b0dbbaa6e 100644 --- a/plumbing/transport/ssh/common.go +++ b/plumbing/transport/ssh/common.go @@ -3,7 +3,9 @@ package ssh import ( "context" + "errors" "fmt" + "net" "reflect" "strconv" @@ -90,8 +92,13 @@ 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() + if errors.Is(err, net.ErrClosed) { + return nil + } + + return err } // connect connects to the SSH server, unless a AuthMethod was set with From 3e3eda06723bdb43aa9d2a4939c5681ad1289567 Mon Sep 17 00:00:00 2001 From: David Cuadrado Date: Thu, 25 Mar 2021 12:58:24 -0500 Subject: [PATCH 2/4] Compatibility for go 1.13 Because it's required by the pipeline --- plumbing/transport/ssh/common.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go index b0dbbaa6e..46e79134c 100644 --- a/plumbing/transport/ssh/common.go +++ b/plumbing/transport/ssh/common.go @@ -3,11 +3,10 @@ package ssh import ( "context" - "errors" "fmt" - "net" "reflect" "strconv" + "strings" "github.com/go-git/go-git/v5/plumbing/transport" "github.com/go-git/go-git/v5/plumbing/transport/internal/common" @@ -94,7 +93,8 @@ func (c *command) Close() error { _ = c.Session.Close() err := c.client.Close() - if errors.Is(err, net.ErrClosed) { + //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 } From 1f2daa6557b122ea71cb7baa3b501795b61f85aa Mon Sep 17 00:00:00 2001 From: David Cuadrado Date: Fri, 26 Mar 2021 09:35:27 -0500 Subject: [PATCH 3/4] Add test for allowing to close a command when the client is already closed This test is for issue #70 --- plumbing/transport/ssh/common_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plumbing/transport/ssh/common_test.go b/plumbing/transport/ssh/common_test.go index 87c1148a0..e04a9c5dc 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 } From 39b4fe2dc6a179daf620c0bddd6c0f558a83919c Mon Sep 17 00:00:00 2001 From: David Cuadrado Date: Fri, 26 Mar 2021 09:50:50 -0500 Subject: [PATCH 4/4] Add debug information for broken test --- worktree_commit_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/worktree_commit_test.go b/worktree_commit_test.go index 3bc112b29..cb94a2b6c 100644 --- a/worktree_commit_test.go +++ b/worktree_commit_test.go @@ -3,9 +3,11 @@ package git import ( "bytes" "io/ioutil" + "log" "os" "os/exec" "path/filepath" + "runtime" "strings" "time" @@ -309,6 +311,8 @@ func (s *WorktreeSuite) TestJustStoreObjectsNotAlreadyStored(c *C) { infoLicenseSecond, err := fsDotgit.Stat(filepath.Join("objects", "04", "84eba0d41636ba71fa612c78559cd6c3006cde")) c.Assert(err, IsNil) + + log.Printf("comparing mod time: %v == %v on %v (%v)", infoLicenseSecond.ModTime(), infoLicense.ModTime(), runtime.GOOS, runtime.GOARCH) c.Assert(infoLicenseSecond.ModTime(), Equals, infoLicense.ModTime()) // object of LICENSE should have the same timestamp because no additional write operation was performed }