diff options
author | Santiago M. Mola <santi@mola.io> | 2016-12-19 23:36:44 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-19 23:36:44 +0100 |
commit | 90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (patch) | |
tree | fc8c14e82974be6ff49e842328ec3206ebf1b4c2 /repository_test.go | |
parent | 725ade0de6f60549e65cc4d94094b1f5ed48587f (diff) | |
download | go-git-90d67bb648ae32d5b1a0f7b1af011da6dfb24315.tar.gz |
remote: add Push (#178)
* remote: add Push.
* add Push method to Remote.
* add method Push to Repository.
* examples: add push example.
* requested changes
* add tests, fixes
Diffstat (limited to 'repository_test.go')
-rw-r--r-- | repository_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go index 4d17dce..12ae858 100644 --- a/repository_test.go +++ b/repository_test.go @@ -15,6 +15,7 @@ import ( "gopkg.in/src-d/go-git.v4/storage/memory" . "gopkg.in/check.v1" + "gopkg.in/src-d/go-git.v4/storage/filesystem" ) type RepositorySuite struct { @@ -331,6 +332,59 @@ func (s *RepositorySuite) TestPullA(c *C) { c.Assert(branch.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881") } +func (s *RepositorySuite) TestPushToEmptyRepository(c *C) { + srcFs := fixtures.Basic().One().DotGit() + sto, err := filesystem.NewStorage(srcFs) + c.Assert(err, IsNil) + + dstFs := fixtures.ByTag("empty").One().DotGit() + url := fmt.Sprintf("file://%s", dstFs.Base()) + + r, err := NewRepository(sto) + c.Assert(err, IsNil) + + _, err = r.CreateRemote(&config.RemoteConfig{ + Name: "myremote", + URL: url, + }) + c.Assert(err, IsNil) + + err = r.Push(&PushOptions{RemoteName: "myremote"}) + c.Assert(err, IsNil) + + sto, err = filesystem.NewStorage(dstFs) + c.Assert(err, IsNil) + dstRepo, err := NewRepository(sto) + c.Assert(err, IsNil) + + iter, err := sto.IterReferences() + c.Assert(err, IsNil) + err = iter.ForEach(func(ref *plumbing.Reference) error { + if !ref.IsBranch() { + return nil + } + + dstRef, err := dstRepo.Reference(ref.Name(), true) + c.Assert(err, IsNil) + c.Assert(dstRef, DeepEquals, ref) + + return nil + }) + c.Assert(err, IsNil) +} + +func (s *RepositorySuite) TestPushNonExistentRemote(c *C) { + srcFs := fixtures.Basic().One().DotGit() + sto, err := filesystem.NewStorage(srcFs) + c.Assert(err, IsNil) + + r, err := NewRepository(sto) + c.Assert(err, IsNil) + + err = r.Push(&PushOptions{RemoteName: "myremote"}) + c.Assert(err, ErrorMatches, ".*remote not found.*") +} + func (s *RepositorySuite) TestIsEmpty(c *C) { r := NewMemoryRepository() |