aboutsummaryrefslogtreecommitdiffstats
path: root/remote_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'remote_test.go')
-rw-r--r--remote_test.go99
1 files changed, 86 insertions, 13 deletions
diff --git a/remote_test.go b/remote_test.go
index e2fd8ae..a38675a 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -143,7 +143,7 @@ func (s *RemoteSuite) TestFetchWithNoTags(c *C) {
s.testFetch(c, r, &FetchOptions{
Tags: NoTags,
RefSpecs: []config.RefSpec{
- config.RefSpec("+refs/heads/master:refs/remotes/origin/master"),
+ config.RefSpec("+refs/heads/*:refs/remotes/origin/*"),
},
}, []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f"),
@@ -538,6 +538,42 @@ func (s *RemoteSuite) TestPushNewReference(c *C) {
})
}
+func (s *RemoteSuite) TestPushNewReferenceAndDeleteInBatch(c *C) {
+ fs := fixtures.Basic().One().DotGit()
+ url := c.MkDir()
+ server, err := PlainClone(url, true, &CloneOptions{
+ URL: fs.Root(),
+ })
+
+ r, err := PlainClone(c.MkDir(), true, &CloneOptions{
+ URL: url,
+ })
+ c.Assert(err, IsNil)
+
+ remote, err := r.Remote(DefaultRemoteName)
+ c.Assert(err, IsNil)
+
+ ref, err := r.Reference(plumbing.ReferenceName("refs/heads/master"), true)
+ c.Assert(err, IsNil)
+
+ err = remote.Push(&PushOptions{RefSpecs: []config.RefSpec{
+ "refs/heads/master:refs/heads/branch2",
+ ":refs/heads/branch",
+ }})
+ c.Assert(err, IsNil)
+
+ AssertReferences(c, server, map[string]string{
+ "refs/heads/branch2": ref.Hash().String(),
+ })
+
+ AssertReferences(c, r, map[string]string{
+ "refs/remotes/origin/branch2": ref.Hash().String(),
+ })
+
+ _, err = server.Storer.Reference(plumbing.ReferenceName("refs/heads/branch"))
+ c.Assert(err, Equals, plumbing.ErrReferenceNotFound)
+}
+
func (s *RemoteSuite) TestPushInvalidEndpoint(c *C) {
r := newRemote(nil, &config.RemoteConfig{Name: "foo", URLs: []string{"http://\\"}})
err := r.Push(&PushOptions{RemoteName: "foo"})
@@ -589,20 +625,57 @@ func (s *RemoteSuite) TestPushWrongRemoteName(c *C) {
}
func (s *RemoteSuite) TestGetHaves(c *C) {
- st := memory.NewStorage()
- st.SetReference(plumbing.NewReferenceFromStrings(
- "foo", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f",
- ))
-
- st.SetReference(plumbing.NewReferenceFromStrings(
- "bar", "fe6cb94756faa81e5ed9240f9191b833db5f40ae",
- ))
+ f := fixtures.Basic().One()
+ sto, err := filesystem.NewStorage(f.DotGit())
+ c.Assert(err, IsNil)
- st.SetReference(plumbing.NewReferenceFromStrings(
- "qux", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f",
- ))
+ var localRefs = []*plumbing.Reference{
+ plumbing.NewReferenceFromStrings(
+ "foo",
+ "f7b877701fbf855b44c0a9e86f3fdce2c298b07f",
+ ),
+ plumbing.NewReferenceFromStrings(
+ "bar",
+ "fe6cb94756faa81e5ed9240f9191b833db5f40ae",
+ ),
+ plumbing.NewReferenceFromStrings(
+ "qux",
+ "f7b877701fbf855b44c0a9e86f3fdce2c298b07f",
+ ),
+ }
- l, err := getHaves(st)
+ l, err := getHaves(localRefs, memory.NewStorage(), sto)
c.Assert(err, IsNil)
c.Assert(l, HasLen, 2)
}
+
+func (s *RemoteSuite) TestList(c *C) {
+ repo := fixtures.Basic().One()
+ remote := newRemote(memory.NewStorage(), &config.RemoteConfig{
+ Name: DefaultRemoteName,
+ URLs: []string{repo.URL},
+ })
+
+ refs, err := remote.List(&ListOptions{})
+ c.Assert(err, IsNil)
+
+ expected := []*plumbing.Reference{
+ plumbing.NewSymbolicReference("HEAD", "refs/heads/master"),
+ plumbing.NewReferenceFromStrings("refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
+ plumbing.NewReferenceFromStrings("refs/heads/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"),
+ plumbing.NewReferenceFromStrings("refs/pull/1/head", "b8e471f58bcbca63b07bda20e428190409c2db47"),
+ plumbing.NewReferenceFromStrings("refs/pull/2/head", "9632f02833b2f9613afb5e75682132b0b22e4a31"),
+ plumbing.NewReferenceFromStrings("refs/pull/2/merge", "c37f58a130ca555e42ff96a071cb9ccb3f437504"),
+ }
+ c.Assert(len(refs), Equals, len(expected))
+ for _, e := range expected {
+ found := false
+ for _, r := range refs {
+ if r.Name() == e.Name() {
+ found = true
+ c.Assert(r, DeepEquals, e)
+ }
+ }
+ c.Assert(found, Equals, true)
+ }
+}