aboutsummaryrefslogtreecommitdiffstats
path: root/remote_test.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-04-27 14:02:03 +0200
committerSantiago M. Mola <santi@mola.io>2017-04-27 14:02:03 +0200
commit38bd9e82fd3d83fd9a82678ec89227aeda2c3b78 (patch)
tree4b559d70055114ee6fbfb0b3d87768e4e5694f10 /remote_test.go
parent64cd72debb2a94a49de5ffd3c3a6bfd626df7340 (diff)
downloadgo-git-38bd9e82fd3d83fd9a82678ec89227aeda2c3b78.tar.gz
support force push (refspec with +)
* add support for force push * add support for push of new references
Diffstat (limited to 'remote_test.go')
-rw-r--r--remote_test.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/remote_test.go b/remote_test.go
index 2cd80cf..d48b6ca 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -266,6 +266,93 @@ 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 := fmt.Sprintf("file://%s", 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 := fmt.Sprintf("file://%s", 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 := fmt.Sprintf("file://%s", 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{})