aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/transport/ssh/common.go9
-rw-r--r--plumbing/transport/ssh/common_test.go21
-rw-r--r--worktree_commit_test.go4
3 files changed, 33 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
}
diff --git a/worktree_commit_test.go b/worktree_commit_test.go
index 3bc112b..cb94a2b 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
}