diff options
Diffstat (limited to 'plumbing/transport/file')
-rw-r--r-- | plumbing/transport/file/common.go | 72 | ||||
-rw-r--r-- | plumbing/transport/file/common_test.go | 9 | ||||
-rw-r--r-- | plumbing/transport/file/fetch_pack_test.go | 48 |
3 files changed, 129 insertions, 0 deletions
diff --git a/plumbing/transport/file/common.go b/plumbing/transport/file/common.go new file mode 100644 index 0000000..82cbba2 --- /dev/null +++ b/plumbing/transport/file/common.go @@ -0,0 +1,72 @@ +package file + +import ( + "io" + "os/exec" + + "gopkg.in/src-d/go-git.v4/plumbing/transport" + "gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common" +) + +// DefaultClient is the default local client. +var DefaultClient = NewClient( + transport.UploadPackServiceName, + transport.ReceivePackServiceName, +) + +type runner struct { + UploadPackBin string + ReceivePackBin string +} + +// NewClient returns a new local client using the given git-upload-pack and +// git-receive-pack binaries. +func NewClient(uploadPackBin, receivePackBin string) transport.Client { + return common.NewClient(&runner{ + UploadPackBin: uploadPackBin, + ReceivePackBin: receivePackBin, + }) +} + +func (r *runner) Command(cmd string, ep transport.Endpoint) (common.Command, error) { + return &command{cmd: exec.Command(cmd, ep.Path)}, nil +} + +type command struct { + cmd *exec.Cmd + closed bool +} + +func (c *command) SetAuth(auth transport.AuthMethod) error { + if auth != nil { + return transport.ErrInvalidAuthMethod + } + + return nil +} + +func (c *command) Start() error { + return c.cmd.Start() +} + +func (c *command) StderrPipe() (io.Reader, error) { + return c.cmd.StderrPipe() +} + +func (c *command) StdinPipe() (io.WriteCloser, error) { + return c.cmd.StdinPipe() +} + +func (c *command) StdoutPipe() (io.Reader, error) { + return c.cmd.StdoutPipe() +} + +// Close waits for the command to exit. +func (c *command) Close() error { + return c.cmd.Process.Kill() +} + +func (c *command) Wait() error { + defer func() { c.closed = true }() + return c.cmd.Wait() +} diff --git a/plumbing/transport/file/common_test.go b/plumbing/transport/file/common_test.go new file mode 100644 index 0000000..94ca4c9 --- /dev/null +++ b/plumbing/transport/file/common_test.go @@ -0,0 +1,9 @@ +package file + +import ( + "testing" + + . "gopkg.in/check.v1" +) + +func Test(t *testing.T) { TestingT(t) } diff --git a/plumbing/transport/file/fetch_pack_test.go b/plumbing/transport/file/fetch_pack_test.go new file mode 100644 index 0000000..80f11ee --- /dev/null +++ b/plumbing/transport/file/fetch_pack_test.go @@ -0,0 +1,48 @@ +package file + +import ( + "fmt" + "os/exec" + + "gopkg.in/src-d/go-git.v4/fixtures" + "gopkg.in/src-d/go-git.v4/plumbing/transport" + "gopkg.in/src-d/go-git.v4/plumbing/transport/test" + + . "gopkg.in/check.v1" +) + +type FetchPackSuite struct { + fixtures.Suite + test.FetchPackSuite +} + +var _ = Suite(&FetchPackSuite{}) + +func (s *FetchPackSuite) SetUpSuite(c *C) { + s.Suite.SetUpSuite(c) + + if err := exec.Command("git", "--version").Run(); err != nil { + c.Skip("git command not found") + } + + s.FetchPackSuite.Client = DefaultClient + + fixture := fixtures.Basic().One() + path := fixture.DotGit().Base() + url := fmt.Sprintf("file://%s", path) + ep, err := transport.NewEndpoint(url) + c.Assert(err, IsNil) + s.Endpoint = ep + + fixture = fixtures.ByTag("empty").One() + path = fixture.DotGit().Base() + url = fmt.Sprintf("file://%s", path) + ep, err = transport.NewEndpoint(url) + c.Assert(err, IsNil) + s.EmptyEndpoint = ep + + url = fmt.Sprintf("file://%s/%s", fixtures.DataFolder, "non-existent") + ep, err = transport.NewEndpoint(url) + c.Assert(err, IsNil) + s.NonExistentEndpoint = ep +} |