aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/file/client.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-01-04 11:18:41 +0100
committerGitHub <noreply@github.com>2017-01-04 11:18:41 +0100
commit841abfb7dc640755c443432064252907e3e55c95 (patch)
tree8af69dcd3b301a10a3e493e2cd805cdec6dcaecd /plumbing/transport/file/client.go
parent90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (diff)
downloadgo-git-841abfb7dc640755c443432064252907e3e55c95.tar.gz
server: add git server implementation (#190)
* server: add generic server implementation (transport-independent), both for git-upload-pack and git-receive-pack. * server: move internal functions to internal/common. * cli: add git-receive-pack and git-upload-pack implementations. * format/packfile: add UpdateObjectStorage function, extracted from Remote. * transport: implement tranport RPC-like, only with git-upload-pack and git-receive-pack methods. Client renamed to Transport. * storer: add storer.Storer interface. * protocol/packp: add UploadPackResponse constructor with packfile. * protocol/packp: fix UploadPackResponse encoding, add tests. * protocol/packp/capability: implement All.
Diffstat (limited to 'plumbing/transport/file/client.go')
-rw-r--r--plumbing/transport/file/client.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/plumbing/transport/file/client.go b/plumbing/transport/file/client.go
new file mode 100644
index 0000000..5484009
--- /dev/null
+++ b/plumbing/transport/file/client.go
@@ -0,0 +1,82 @@
+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.Transport {
+ return common.NewClient(&runner{
+ UploadPackBin: uploadPackBin,
+ ReceivePackBin: receivePackBin,
+ })
+}
+
+func (r *runner) Command(cmd string, ep transport.Endpoint) (common.Command, error) {
+ switch cmd {
+ case transport.UploadPackServiceName:
+ cmd = r.UploadPackBin
+ case transport.ReceivePackServiceName:
+ cmd = r.ReceivePackBin
+ }
+ 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 {
+ if c.closed {
+ return nil
+ }
+
+ return c.cmd.Process.Kill()
+}
+
+func (c *command) Wait() error {
+ defer func() { c.closed = true }()
+ return c.cmd.Wait()
+}