aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2021-05-02 23:40:08 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2021-05-02 23:40:08 +0200
commit01df7536992af375a54bbedf45369a475953e372 (patch)
tree8435050f4388f15b3a85d135a3f7d11b1ff61540 /plumbing
parent67af9d7223b0cc643025d958c592291f7475ac75 (diff)
downloadgo-git-01df7536992af375a54bbedf45369a475953e372.tar.gz
*: use go-billy instead of os calls
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/protocol/packp/advrefs_test.go67
-rw-r--r--plumbing/protocol/packp/ulreq_encode_test.go5
-rw-r--r--plumbing/protocol/packp/ulreq_test.go79
-rw-r--r--plumbing/transport/ssh/auth_method.go2
-rw-r--r--plumbing/transport/ssh/auth_method_test.go26
-rw-r--r--plumbing/transport/ssh/upload_pack_test.go5
6 files changed, 31 insertions, 153 deletions
diff --git a/plumbing/protocol/packp/advrefs_test.go b/plumbing/protocol/packp/advrefs_test.go
index d163e1f..1b8db98 100644
--- a/plumbing/protocol/packp/advrefs_test.go
+++ b/plumbing/protocol/packp/advrefs_test.go
@@ -2,9 +2,7 @@ package packp
import (
"bytes"
- "fmt"
"io"
- "strings"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/pktline"
@@ -380,68 +378,3 @@ func (s *AdvRefsDecodeEncodeSuite) TestAllSmartBug(c *C) {
s.test(c, input, expected, false)
}
-
-func ExampleAdvRefs_Decode() {
- // Here is a raw advertised-ref message.
- raw := "" +
- "0065a6930aaee06755d1bdcfd943fbf614e4d92bb0c7 HEAD\x00multi_ack ofs-delta symref=HEAD:/refs/heads/master\n" +
- "003fa6930aaee06755d1bdcfd943fbf614e4d92bb0c7 refs/heads/master\n" +
- "00441111111111111111111111111111111111111111 refs/tags/v2.6.11-tree\n" +
- "00475555555555555555555555555555555555555555 refs/tags/v2.6.11-tree^{}\n" +
- "0035shallow 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c\n" +
- "0000"
-
- // Use the raw message as our input.
- input := strings.NewReader(raw)
-
- // Decode the input into a newly allocated AdvRefs value.
- ar := NewAdvRefs()
- _ = ar.Decode(input) // error check ignored for brevity
-
- // Do something interesting with the AdvRefs, e.g. print its contents.
- fmt.Println("head =", ar.Head)
- fmt.Println("capabilities =", ar.Capabilities.String())
- fmt.Println("...")
- fmt.Println("shallows =", ar.Shallows)
- // Output: head = a6930aaee06755d1bdcfd943fbf614e4d92bb0c7
- // capabilities = multi_ack ofs-delta symref=HEAD:/refs/heads/master
- // ...
- // shallows = [5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c]
-}
-
-func ExampleAdvRefs_Encode() {
- // Create an AdvRefs with the contents you want...
- ar := NewAdvRefs()
-
- // ...add a hash for the HEAD...
- head := plumbing.NewHash("1111111111111111111111111111111111111111")
- ar.Head = &head
-
- // ...add some server capabilities...
- ar.Capabilities.Add(capability.MultiACK)
- ar.Capabilities.Add(capability.OFSDelta)
- ar.Capabilities.Add(capability.SymRef, "HEAD:/refs/heads/master")
-
- // ...add a couple of references...
- ar.References["refs/heads/master"] = plumbing.NewHash("2222222222222222222222222222222222222222")
- ar.References["refs/tags/v1"] = plumbing.NewHash("3333333333333333333333333333333333333333")
-
- // ...including a peeled ref...
- ar.Peeled["refs/tags/v1"] = plumbing.NewHash("4444444444444444444444444444444444444444")
-
- // ...and finally add a shallow
- ar.Shallows = append(ar.Shallows, plumbing.NewHash("5555555555555555555555555555555555555555"))
-
- // Encode the packpContents to a bytes.Buffer.
- // You can encode into stdout too, but you will not be able
- // see the '\x00' after "HEAD".
- var buf bytes.Buffer
- _ = ar.Encode(&buf) // error checks ignored for brevity
-
- // Print the contents of the buffer as a quoted string.
- // Printing is as a non-quoted string will be prettier but you
- // will miss the '\x00' after "HEAD".
- fmt.Printf("%q", buf.String())
- // Output:
- // "00651111111111111111111111111111111111111111 HEAD\x00multi_ack ofs-delta symref=HEAD:/refs/heads/master\n003f2222222222222222222222222222222222222222 refs/heads/master\n003a3333333333333333333333333333333333333333 refs/tags/v1\n003d4444444444444444444444444444444444444444 refs/tags/v1^{}\n0035shallow 5555555555555555555555555555555555555555\n0000"
-}
diff --git a/plumbing/protocol/packp/ulreq_encode_test.go b/plumbing/protocol/packp/ulreq_encode_test.go
index a16e321..ba6df1a 100644
--- a/plumbing/protocol/packp/ulreq_encode_test.go
+++ b/plumbing/protocol/packp/ulreq_encode_test.go
@@ -2,6 +2,7 @@ package packp
import (
"bytes"
+ "runtime"
"time"
"github.com/go-git/go-git/v5/plumbing"
@@ -236,6 +237,10 @@ func (s *UlReqEncodeSuite) TestDepthSinceUTC(c *C) {
}
func (s *UlReqEncodeSuite) TestDepthSinceNonUTC(c *C) {
+ if runtime.GOOS == "js" {
+ c.Skip("time.LoadLocation not supported in wasm")
+ }
+
ur := NewUploadRequest()
ur.Wants = append(ur.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))
berlin, err := time.LoadLocation("Europe/Berlin")
diff --git a/plumbing/protocol/packp/ulreq_test.go b/plumbing/protocol/packp/ulreq_test.go
index a0bb401..0b3b616 100644
--- a/plumbing/protocol/packp/ulreq_test.go
+++ b/plumbing/protocol/packp/ulreq_test.go
@@ -1,13 +1,9 @@
package packp
import (
- "fmt"
- "os"
- "strings"
"time"
"github.com/go-git/go-git/v5/plumbing"
- "github.com/go-git/go-git/v5/plumbing/format/pktline"
"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability"
. "gopkg.in/check.v1"
@@ -111,78 +107,3 @@ func (s *UlReqSuite) TestValidateConflictMultiACK(c *C) {
err := r.Validate()
c.Assert(err, NotNil)
}
-
-func ExampleUploadRequest_Encode() {
- // Create an empty UlReq with the contents you want...
- ur := NewUploadRequest()
-
- // Add a couple of wants
- ur.Wants = append(ur.Wants, plumbing.NewHash("3333333333333333333333333333333333333333"))
- ur.Wants = append(ur.Wants, plumbing.NewHash("1111111111111111111111111111111111111111"))
- ur.Wants = append(ur.Wants, plumbing.NewHash("2222222222222222222222222222222222222222"))
-
- // And some capabilities you will like the server to use
- ur.Capabilities.Add(capability.OFSDelta)
- ur.Capabilities.Add(capability.SymRef, "HEAD:/refs/heads/master")
-
- // Add a couple of shallows
- ur.Shallows = append(ur.Shallows, plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
- ur.Shallows = append(ur.Shallows, plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
-
- // And retrict the answer of the server to commits newer than "2015-01-02 03:04:05 UTC"
- since := time.Date(2015, time.January, 2, 3, 4, 5, 0, time.UTC)
- ur.Depth = DepthSince(since)
-
- // Create a new Encode for the stdout...
- e := newUlReqEncoder(os.Stdout)
- // ...and encode the upload-request to it.
- _ = e.Encode(ur) // ignoring errors for brevity
- // Output:
- // 005bwant 1111111111111111111111111111111111111111 ofs-delta symref=HEAD:/refs/heads/master
- // 0032want 2222222222222222222222222222222222222222
- // 0032want 3333333333333333333333333333333333333333
- // 0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- // 0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
- // 001cdeepen-since 1420167845
- // 0000
-}
-
-func ExampleUploadRequest_Decode() {
- // Here is a raw advertised-ref message.
- raw := "" +
- "005bwant 1111111111111111111111111111111111111111 ofs-delta symref=HEAD:/refs/heads/master\n" +
- "0032want 2222222222222222222222222222222222222222\n" +
- "0032want 3333333333333333333333333333333333333333\n" +
- "0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +
- "0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +
- "001cdeepen-since 1420167845\n" + // 2015-01-02 03:04:05 +0000 UTC
- pktline.FlushString
-
- // Use the raw message as our input.
- input := strings.NewReader(raw)
-
- // Create the Decoder reading from our input.
- d := newUlReqDecoder(input)
-
- // Decode the input into a newly allocated UlReq value.
- ur := NewUploadRequest()
- _ = d.Decode(ur) // error check ignored for brevity
-
- // Do something interesting with the UlReq, e.g. print its contents.
- fmt.Println("capabilities =", ur.Capabilities.String())
- fmt.Println("wants =", ur.Wants)
- fmt.Println("shallows =", ur.Shallows)
- switch depth := ur.Depth.(type) {
- case DepthCommits:
- fmt.Println("depth =", int(depth))
- case DepthSince:
- fmt.Println("depth =", time.Time(depth))
- case DepthReference:
- fmt.Println("depth =", string(depth))
- }
- // Output:
- // capabilities = ofs-delta symref=HEAD:/refs/heads/master
- // wants = [1111111111111111111111111111111111111111 2222222222222222222222222222222222222222 3333333333333333333333333333333333333333]
- // shallows = [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb]
- // depth = 2015-01-02 03:04:05 +0000 UTC
-}
diff --git a/plumbing/transport/ssh/auth_method.go b/plumbing/transport/ssh/auth_method.go
index 568ec86..3514669 100644
--- a/plumbing/transport/ssh/auth_method.go
+++ b/plumbing/transport/ssh/auth_method.go
@@ -11,7 +11,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/mitchellh/go-homedir"
- "github.com/xanzy/ssh-agent"
+ sshagent "github.com/xanzy/ssh-agent"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
)
diff --git a/plumbing/transport/ssh/auth_method_test.go b/plumbing/transport/ssh/auth_method_test.go
index ade344f..b275018 100644
--- a/plumbing/transport/ssh/auth_method_test.go
+++ b/plumbing/transport/ssh/auth_method_test.go
@@ -3,10 +3,12 @@ package ssh
import (
"bufio"
"fmt"
- "io/ioutil"
"os"
+ "runtime"
"strings"
+ "github.com/go-git/go-billy/v5/osfs"
+ "github.com/go-git/go-billy/v5/util"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/testdata"
@@ -108,6 +110,10 @@ func (s *SuiteCommon) TestPublicKeysCallbackString(c *C) {
c.Assert(a.String(), Equals, fmt.Sprintf("user: test, name: %s", PublicKeysCallbackName))
}
func (s *SuiteCommon) TestNewSSHAgentAuth(c *C) {
+ if runtime.GOOS == "js" {
+ c.Skip("tcp connections are not available in wasm")
+ }
+
if os.Getenv("SSH_AUTH_SOCK") == "" {
c.Skip("SSH_AUTH_SOCK or SSH_TEST_PRIVATE_KEY are required")
}
@@ -153,12 +159,16 @@ func (*SuiteCommon) TestNewPublicKeysWithEncryptedEd25519PEM(c *C) {
}
func (*SuiteCommon) TestNewPublicKeysFromFile(c *C) {
- f, err := ioutil.TempFile("", "ssh-test")
+ if runtime.GOOS == "js" {
+ c.Skip("not available in wasm")
+ }
+
+ f, err := util.TempFile(osfs.Default, "", "ssh-test")
c.Assert(err, IsNil)
_, err = f.Write(testdata.PEMBytes["rsa"])
c.Assert(err, IsNil)
c.Assert(f.Close(), IsNil)
- defer os.RemoveAll(f.Name())
+ defer osfs.Default.Remove(f.Name())
auth, err := NewPublicKeysFromFile("foo", f.Name(), "")
c.Assert(err, IsNil)
@@ -172,9 +182,13 @@ func (*SuiteCommon) TestNewPublicKeysWithInvalidPEM(c *C) {
}
func (*SuiteCommon) TestNewKnownHostsCallback(c *C) {
+ if runtime.GOOS == "js" {
+ c.Skip("not available in wasm")
+ }
+
var mock = mockKnownHosts{}
- f, err := ioutil.TempFile("", "known-hosts")
+ f, err := util.TempFile(osfs.Default, "", "known-hosts")
c.Assert(err, IsNil)
_, err = f.Write(mock.knownHosts())
@@ -183,9 +197,9 @@ func (*SuiteCommon) TestNewKnownHostsCallback(c *C) {
err = f.Close()
c.Assert(err, IsNil)
- defer os.RemoveAll(f.Name())
+ defer util.RemoveAll(osfs.Default, f.Name())
- f, err = os.Open(f.Name())
+ f, err = osfs.Default.Open(f.Name())
c.Assert(err, IsNil)
defer f.Close()
diff --git a/plumbing/transport/ssh/upload_pack_test.go b/plumbing/transport/ssh/upload_pack_test.go
index 1bcb82b..e65e04a 100644
--- a/plumbing/transport/ssh/upload_pack_test.go
+++ b/plumbing/transport/ssh/upload_pack_test.go
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"sync"
@@ -32,6 +33,10 @@ type UploadPackSuite struct {
var _ = Suite(&UploadPackSuite{})
func (s *UploadPackSuite) SetUpSuite(c *C) {
+ if runtime.GOOS == "js" {
+ c.Skip("tcp connections are not available in wasm")
+ }
+
l, err := net.Listen("tcp", "localhost:0")
c.Assert(err, IsNil)