| 1 |
package file |
| 2 |
|
| 3 |
import ( |
| 4 |
"io" |
| 5 |
"os" |
| 6 |
"path/filepath" |
| 7 |
"strings" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/go-git/go-git/v5/plumbing/transport" |
| 11 |
|
| 12 |
. "gopkg.in/check.v1" |
| 13 |
) |
| 14 |
|
| 15 |
func Test(t *testing.T) { TestingT(t) } |
| 16 |
|
| 17 |
type ClientSuite struct { |
| 18 |
CommonSuite |
| 19 |
} |
| 20 |
|
| 21 |
var _ = Suite(&ClientSuite{}) |
| 22 |
|
| 23 |
func (s *ClientSuite) TestCommand(c *C) { |
| 24 |
runner := &runner{ |
| 25 |
UploadPackBin: transport.UploadPackServiceName, |
| 26 |
ReceivePackBin: transport.ReceivePackServiceName, |
| 27 |
} |
| 28 |
ep, err := transport.NewEndpoint(filepath.Join("fake", "repo")) |
| 29 |
c.Assert(err, IsNil) |
| 30 |
var emptyAuth transport.AuthMethod |
| 31 |
_, err = runner.Command("git-receive-pack", ep, emptyAuth) |
| 32 |
c.Assert(err, IsNil) |
| 33 |
|
| 34 |
// Make sure we get an error for one that doesn't exist. |
| 35 |
_, err = runner.Command("git-fake-command", ep, emptyAuth) |
| 36 |
c.Assert(err, NotNil) |
| 37 |
} |
| 38 |
|
| 39 |
const bareConfig = `[core] |
| 40 |
repositoryformatversion = 0 |
| 41 |
filemode = true |
| 42 |
bare = true` |
| 43 |
|
| 44 |
func prepareRepo(c *C, path string) *transport.Endpoint { |
| 45 |
ep, err := transport.NewEndpoint(path) |
| 46 |
c.Assert(err, IsNil) |
| 47 |
|
| 48 |
// git-receive-pack refuses to update refs/heads/master on non-bare repo |
| 49 |
// so we ensure bare repo config. |
| 50 |
config := filepath.Join(path, "config") |
| 51 |
if _, err := os.Stat(config); err == nil { |
| 52 |
f, err := os.OpenFile(config, os.O_TRUNC|os.O_WRONLY, 0) |
| 53 |
c.Assert(err, IsNil) |
| 54 |
content := strings.NewReader(bareConfig) |
| 55 |
_, err = io.Copy(f, content) |
| 56 |
c.Assert(err, IsNil) |
| 57 |
c.Assert(f.Close(), IsNil) |
| 58 |
} |
| 59 |
|
| 60 |
return ep |
| 61 |
} |