diff options
author | Javi Fontan <jfontan@gmail.com> | 2018-04-16 19:01:49 +0200 |
---|---|---|
committer | Javi Fontan <jfontan@gmail.com> | 2018-04-16 19:01:49 +0200 |
commit | 75da83739f25f528bf242341d62e01b773329470 (patch) | |
tree | c3fbaf323e0e1a46364f39c97a7721b8f53a7635 /remote_test.go | |
parent | 0db54e829f81a28f71c22d54c03daba5ec144c8d (diff) | |
download | go-git-75da83739f25f528bf242341d62e01b773329470.tar.gz |
git: remote, Add shallow commits instead of substituting. Fixes #412
updateShallow substituted the previous shallow list with the one
returned by the UploadPackResponse. If the repository had previous
shallow commits these are deleted from the list.
This change adds the new shallow hashes to the old ones.
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'remote_test.go')
-rw-r--r-- | remote_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/remote_test.go b/remote_test.go index e586e7a..82ec1fc 100644 --- a/remote_test.go +++ b/remote_test.go @@ -9,6 +9,7 @@ import ( "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp" "gopkg.in/src-d/go-git.v4/plumbing/storer" "gopkg.in/src-d/go-git.v4/storage" "gopkg.in/src-d/go-git.v4/storage/filesystem" @@ -741,3 +742,54 @@ func (s *RemoteSuite) TestList(c *C) { c.Assert(found, Equals, true) } } + +func (s *RemoteSuite) TestUpdateShallows(c *C) { + hashes := []plumbing.Hash{ + plumbing.NewHash("0000000000000000000000000000000000000001"), + plumbing.NewHash("0000000000000000000000000000000000000002"), + plumbing.NewHash("0000000000000000000000000000000000000003"), + plumbing.NewHash("0000000000000000000000000000000000000004"), + plumbing.NewHash("0000000000000000000000000000000000000005"), + plumbing.NewHash("0000000000000000000000000000000000000006"), + } + + tests := []struct { + hashes []plumbing.Hash + result []plumbing.Hash + }{ + // add to empty shallows + {hashes[0:2], hashes[0:2]}, + // add new hashes + {hashes[2:4], hashes[0:4]}, + // add some hashes already in shallow list + {hashes[2:6], hashes[0:6]}, + // add all hashes + {hashes[0:6], hashes[0:6]}, + // add empty list + {nil, hashes[0:6]}, + } + + remote := newRemote(memory.NewStorage(), &config.RemoteConfig{ + Name: DefaultRemoteName, + }) + + shallows, err := remote.s.Shallow() + c.Assert(err, IsNil) + c.Assert(len(shallows), Equals, 0) + + resp := new(packp.UploadPackResponse) + o := &FetchOptions{ + Depth: 1, + } + + for _, t := range tests { + resp.Shallows = t.hashes + err = remote.updateShallow(o, resp) + c.Assert(err, IsNil) + + shallow, err := remote.s.Shallow() + c.Assert(err, IsNil) + c.Assert(len(shallow), Equals, len(t.result)) + c.Assert(shallow, DeepEquals, t.result) + } +} |