diff options
Diffstat (limited to 'remote_test.go')
-rw-r--r-- | remote_test.go | 153 |
1 files changed, 142 insertions, 11 deletions
diff --git a/remote_test.go b/remote_test.go index 2cd80cf..8b2f71c 100644 --- a/remote_test.go +++ b/remote_test.go @@ -2,7 +2,6 @@ package git import ( "bytes" - "fmt" "io" "io/ioutil" "os" @@ -26,9 +25,9 @@ type RemoteSuite struct { var _ = Suite(&RemoteSuite{}) func (s *RemoteSuite) TestFetchInvalidEndpoint(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: "qux"}) - err := r.Fetch(&FetchOptions{}) - c.Assert(err, ErrorMatches, ".*invalid endpoint.*") + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: "http://\\"}) + err := r.Fetch(&FetchOptions{RemoteName: "foo"}) + c.Assert(err, ErrorMatches, ".*invalid character.*") } func (s *RemoteSuite) TestFetchNonExistentEndpoint(c *C) { @@ -215,7 +214,7 @@ func (s *RemoteSuite) TestPushToEmptyRepository(c *C) { c.Assert(err, IsNil) dstFs := fixtures.ByTag("empty").One().DotGit() - url := fmt.Sprintf("file://%s", dstFs.Base()) + url := dstFs.Base() r := newRemote(sto, &config.RemoteConfig{ Name: DefaultRemoteName, @@ -249,11 +248,56 @@ func (s *RemoteSuite) TestPushToEmptyRepository(c *C) { c.Assert(err, IsNil) } +func (s *RemoteSuite) TestPushTags(c *C) { + srcFs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit() + sto, err := filesystem.NewStorage(srcFs) + c.Assert(err, IsNil) + + dstFs := fixtures.ByTag("empty").One().DotGit() + url := dstFs.Base() + + r := newRemote(sto, &config.RemoteConfig{ + Name: DefaultRemoteName, + URL: url, + }) + + rs := config.RefSpec("refs/tags/*:refs/tags/*") + err = r.Push(&PushOptions{ + RefSpecs: []config.RefSpec{rs}, + }) + c.Assert(err, IsNil) + + dstSto, err := filesystem.NewStorage(dstFs) + c.Assert(err, IsNil) + dstRepo, err := Open(dstSto, nil) + c.Assert(err, IsNil) + + ref, err := dstRepo.Storer.Reference(plumbing.ReferenceName("refs/tags/lightweight-tag")) + c.Assert(err, IsNil) + c.Assert(ref, DeepEquals, plumbing.NewReferenceFromStrings("refs/tags/lightweight-tag", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f")) + + ref, err = dstRepo.Storer.Reference(plumbing.ReferenceName("refs/tags/annotated-tag")) + c.Assert(err, IsNil) + c.Assert(ref, DeepEquals, plumbing.NewReferenceFromStrings("refs/tags/annotated-tag", "b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) + + ref, err = dstRepo.Storer.Reference(plumbing.ReferenceName("refs/tags/commit-tag")) + c.Assert(err, IsNil) + c.Assert(ref, DeepEquals, plumbing.NewReferenceFromStrings("refs/tags/commit-tag", "ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc")) + + ref, err = dstRepo.Storer.Reference(plumbing.ReferenceName("refs/tags/blob-tag")) + c.Assert(err, IsNil) + c.Assert(ref, DeepEquals, plumbing.NewReferenceFromStrings("refs/tags/blob-tag", "fe6cb94756faa81e5ed9240f9191b833db5f40ae")) + + ref, err = dstRepo.Storer.Reference(plumbing.ReferenceName("refs/tags/tree-tag")) + c.Assert(err, IsNil) + c.Assert(ref, DeepEquals, plumbing.NewReferenceFromStrings("refs/tags/tree-tag", "152175bf7e5580299fa1f0ba41ef6474cc043b70")) +} + func (s *RemoteSuite) TestPushNoErrAlreadyUpToDate(c *C) { f := fixtures.Basic().One() sto, err := filesystem.NewStorage(f.DotGit()) c.Assert(err, IsNil) - url := fmt.Sprintf("file://%s", f.DotGit().Base()) + url := f.DotGit().Base() r := newRemote(sto, &config.RemoteConfig{ Name: DefaultRemoteName, URL: url, @@ -266,10 +310,97 @@ func (s *RemoteSuite) TestPushNoErrAlreadyUpToDate(c *C) { c.Assert(err, Equals, NoErrAlreadyUpToDate) } +func (s *RemoteSuite) TestPushRejectNonFastForward(c *C) { + f := fixtures.Basic().One() + sto, err := filesystem.NewStorage(f.DotGit()) + c.Assert(err, IsNil) + + dstFs := f.DotGit() + dstSto, err := filesystem.NewStorage(dstFs) + c.Assert(err, IsNil) + + url := dstFs.Base() + r := newRemote(sto, &config.RemoteConfig{ + Name: DefaultRemoteName, + URL: url, + }) + + oldRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch")) + c.Assert(err, IsNil) + c.Assert(oldRef, NotNil) + + err = r.Push(&PushOptions{RefSpecs: []config.RefSpec{ + config.RefSpec("refs/heads/master:refs/heads/branch"), + }}) + c.Assert(err, ErrorMatches, "non-fast-forward update: refs/heads/branch") + + newRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch")) + c.Assert(err, IsNil) + c.Assert(newRef, DeepEquals, oldRef) +} + +func (s *RemoteSuite) TestPushForce(c *C) { + f := fixtures.Basic().One() + sto, err := filesystem.NewStorage(f.DotGit()) + c.Assert(err, IsNil) + + dstFs := f.DotGit() + dstSto, err := filesystem.NewStorage(dstFs) + c.Assert(err, IsNil) + + url := dstFs.Base() + r := newRemote(sto, &config.RemoteConfig{ + Name: DefaultRemoteName, + URL: url, + }) + + oldRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch")) + c.Assert(err, IsNil) + c.Assert(oldRef, NotNil) + + err = r.Push(&PushOptions{RefSpecs: []config.RefSpec{ + config.RefSpec("+refs/heads/master:refs/heads/branch"), + }}) + c.Assert(err, IsNil) + + newRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch")) + c.Assert(err, IsNil) + c.Assert(newRef, Not(DeepEquals), oldRef) +} + +func (s *RemoteSuite) TestPushNewReference(c *C) { + f := fixtures.Basic().One() + sto, err := filesystem.NewStorage(f.DotGit()) + c.Assert(err, IsNil) + + dstFs := f.DotGit() + dstSto, err := filesystem.NewStorage(dstFs) + c.Assert(err, IsNil) + + url := dstFs.Base() + r := newRemote(sto, &config.RemoteConfig{ + Name: DefaultRemoteName, + URL: url, + }) + + oldRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch")) + c.Assert(err, IsNil) + c.Assert(oldRef, NotNil) + + err = r.Push(&PushOptions{RefSpecs: []config.RefSpec{ + config.RefSpec("refs/heads/branch:refs/heads/branch2"), + }}) + c.Assert(err, IsNil) + + newRef, err := dstSto.Reference(plumbing.ReferenceName("refs/heads/branch2")) + c.Assert(err, IsNil) + c.Assert(newRef.Hash(), Equals, oldRef.Hash()) +} + func (s *RemoteSuite) TestPushInvalidEndpoint(c *C) { - r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: "qux"}) - err := r.Push(&PushOptions{}) - c.Assert(err, ErrorMatches, ".*invalid endpoint.*") + r := newRemote(nil, &config.RemoteConfig{Name: "foo", URL: "http://\\"}) + err := r.Push(&PushOptions{RemoteName: "foo"}) + c.Assert(err, ErrorMatches, ".*invalid character.*") } func (s *RemoteSuite) TestPushNonExistentEndpoint(c *C) { @@ -294,7 +425,7 @@ func (s *RemoteSuite) TestPushInvalidFetchOptions(c *C) { func (s *RemoteSuite) TestPushInvalidRefSpec(c *C) { r := newRemote(nil, &config.RemoteConfig{ Name: DefaultRemoteName, - URL: "file:///some-url", + URL: "some-url", }) rs := config.RefSpec("^*$**") @@ -307,7 +438,7 @@ func (s *RemoteSuite) TestPushInvalidRefSpec(c *C) { func (s *RemoteSuite) TestPushWrongRemoteName(c *C) { r := newRemote(nil, &config.RemoteConfig{ Name: DefaultRemoteName, - URL: "file:///some-url", + URL: "some-url", }) err := r.Push(&PushOptions{ |