Debian Codegraph @

plumbing/transport/file/server_test.go

raw
1 package file
2
3 import (
4 "os"
5 "os/exec"
6
7 "github.com/go-git/go-git-fixtures/v4"
8 . "gopkg.in/check.v1"
9 )
10
11 type ServerSuite struct {
12 CommonSuite
13 RemoteName string
14 SrcPath string
15 DstPath string
16 }
17
18 var _ = Suite(&ServerSuite{})
19
20 func (s *ServerSuite) SetUpSuite(c *C) {
21 s.CommonSuite.SetUpSuite(c)
22
23 s.RemoteName = "test"
24
25 fixture := fixtures.Basic().One()
26 s.SrcPath = fixture.DotGit().Root()
27
28 fixture = fixtures.ByTag("empty").One()
29 s.DstPath = fixture.DotGit().Root()
30
31 cmd := exec.Command("git", "remote", "add", s.RemoteName, s.DstPath)
32 cmd.Dir = s.SrcPath
33 c.Assert(cmd.Run(), IsNil)
34 }
35
36 func (s *ServerSuite) TestPush(c *C) {
37 if !s.checkExecPerm(c) {
38 c.Skip("go-git binary has not execution permissions")
39 }
40
41 // git <2.0 cannot push to an empty repository without a refspec.
42 cmd := exec.Command("git", "push",
43 "--receive-pack", s.ReceivePackBin,
44 s.RemoteName, "refs/heads/*:refs/heads/*",
45 )
46 cmd.Dir = s.SrcPath
47 cmd.Env = os.Environ()
48 cmd.Env = append(cmd.Env, "GIT_TRACE=true", "GIT_TRACE_PACKET=true")
49 out, err := cmd.CombinedOutput()
50 c.Assert(err, IsNil, Commentf("combined stdout and stderr:\n%s\n", out))
51 }
52
53 func (s *ServerSuite) TestClone(c *C) {
54 if !s.checkExecPerm(c) {
55 c.Skip("go-git binary has not execution permissions")
56 }
57
58 pathToClone := c.MkDir()
59
60 cmd := exec.Command("git", "clone",
61 "--upload-pack", s.UploadPackBin,
62 s.SrcPath, pathToClone,
63 )
64 cmd.Env = os.Environ()
65 cmd.Env = append(cmd.Env, "GIT_TRACE=true", "GIT_TRACE_PACKET=true")
66 out, err := cmd.CombinedOutput()
67 c.Assert(err, IsNil, Commentf("combined stdout and stderr:\n%s\n", out))
68 }
69
70 func (s *ServerSuite) checkExecPerm(c *C) bool {
71 const userExecPermMask = 0100
72 info, err := os.Stat(s.ReceivePackBin)
73 c.Assert(err, IsNil)
74 return (info.Mode().Perm() & userExecPermMask) == userExecPermMask
75 }