|
9 | 9 |
|
10 | 10 | "gopkg.in/src-d/go-git.v4/config" |
11 | 11 | "gopkg.in/src-d/go-git.v4/plumbing" |
| 12 | + "gopkg.in/src-d/go-git.v4/plumbing/protocol/packp" |
12 | 13 | "gopkg.in/src-d/go-git.v4/plumbing/storer" |
13 | 14 | "gopkg.in/src-d/go-git.v4/storage" |
14 | 15 | "gopkg.in/src-d/go-git.v4/storage/filesystem" |
@@ -741,3 +742,54 @@ func (s *RemoteSuite) TestList(c *C) { |
741 | 742 | c.Assert(found, Equals, true) |
742 | 743 | } |
743 | 744 | } |
| 745 | + |
| 746 | +func (s *RemoteSuite) TestUpdateShallows(c *C) { |
| 747 | + hashes := []plumbing.Hash{ |
| 748 | + plumbing.NewHash("0000000000000000000000000000000000000001"), |
| 749 | + plumbing.NewHash("0000000000000000000000000000000000000002"), |
| 750 | + plumbing.NewHash("0000000000000000000000000000000000000003"), |
| 751 | + plumbing.NewHash("0000000000000000000000000000000000000004"), |
| 752 | + plumbing.NewHash("0000000000000000000000000000000000000005"), |
| 753 | + plumbing.NewHash("0000000000000000000000000000000000000006"), |
| 754 | + } |
| 755 | + |
| 756 | + tests := []struct { |
| 757 | + hashes []plumbing.Hash |
| 758 | + result []plumbing.Hash |
| 759 | + }{ |
| 760 | + // add to empty shallows |
| 761 | + {hashes[0:2], hashes[0:2]}, |
| 762 | + // add new hashes |
| 763 | + {hashes[2:4], hashes[0:4]}, |
| 764 | + // add some hashes already in shallow list |
| 765 | + {hashes[2:6], hashes[0:6]}, |
| 766 | + // add all hashes |
| 767 | + {hashes[0:6], hashes[0:6]}, |
| 768 | + // add empty list |
| 769 | + {nil, hashes[0:6]}, |
| 770 | + } |
| 771 | + |
| 772 | + remote := newRemote(memory.NewStorage(), &config.RemoteConfig{ |
| 773 | + Name: DefaultRemoteName, |
| 774 | + }) |
| 775 | + |
| 776 | + shallows, err := remote.s.Shallow() |
| 777 | + c.Assert(err, IsNil) |
| 778 | + c.Assert(len(shallows), Equals, 0) |
| 779 | + |
| 780 | + resp := new(packp.UploadPackResponse) |
| 781 | + o := &FetchOptions{ |
| 782 | + Depth: 1, |
| 783 | + } |
| 784 | + |
| 785 | + for _, t := range tests { |
| 786 | + resp.Shallows = t.hashes |
| 787 | + err = remote.updateShallow(o, resp) |
| 788 | + c.Assert(err, IsNil) |
| 789 | + |
| 790 | + shallow, err := remote.s.Shallow() |
| 791 | + c.Assert(err, IsNil) |
| 792 | + c.Assert(len(shallow), Equals, len(t.result)) |
| 793 | + c.Assert(shallow, DeepEquals, t.result) |
| 794 | + } |
| 795 | +} |
0 commit comments