Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transport: ssh, fix cloning large repositories #272

Merged
merged 4 commits into from Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion plumbing/transport/ssh/common.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions plumbing/transport/ssh/common_test.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions worktree_commit_test.go
Expand Up @@ -3,9 +3,11 @@ package git
import (
"bytes"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -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
}

Expand Down