aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/packfile_test.go
diff options
context:
space:
mode:
authorJeremy Stribling <strib@alum.mit.edu>2019-01-31 17:02:22 -0800
committerJeremy Stribling <strib@alum.mit.edu>2019-01-31 17:38:04 -0800
commit121898c6d683311330b58b8a8f8e5ff64575706c (patch)
treec94d3c0accbc8d0a05a9d550a068162a525970d7 /plumbing/format/packfile/packfile_test.go
parenta1f6ef44dfed1253ef7f3bc049f66b15f8fc2ab2 (diff)
downloadgo-git-121898c6d683311330b58b8a8f8e5ff64575706c.tar.gz
packfile: get object size correctly for delta objects
Signed-off-by: Jeremy Stribling <strib@alum.mit.edu>
Diffstat (limited to 'plumbing/format/packfile/packfile_test.go')
-rw-r--r--plumbing/format/packfile/packfile_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/plumbing/format/packfile/packfile_test.go b/plumbing/format/packfile/packfile_test.go
index 05dc8a7..455fe65 100644
--- a/plumbing/format/packfile/packfile_test.go
+++ b/plumbing/format/packfile/packfile_test.go
@@ -277,3 +277,29 @@ func getIndexFromIdxFile(r io.Reader) idxfile.Index {
return idxf
}
+
+func (s *PackfileSuite) TestSize(c *C) {
+ f := fixtures.Basic().ByTag("ref-delta").One()
+
+ index := getIndexFromIdxFile(f.Idx())
+ fs := osfs.New("")
+ pf, err := fs.Open(f.Packfile().Name())
+ c.Assert(err, IsNil)
+
+ packfile := packfile.NewPackfile(index, fs, pf)
+ defer packfile.Close()
+
+ // Get the size of binary.jpg, which is not delta-encoded.
+ offset, err := packfile.FindOffset(plumbing.NewHash("d5c0f4ab811897cadf03aec358ae60d21f91c50d"))
+ c.Assert(err, IsNil)
+ size, err := packfile.GetSizeByOffset(offset)
+ c.Assert(err, IsNil)
+ c.Assert(size, Equals, int64(76110))
+
+ // Get the size of the root commit, which is delta-encoded.
+ offset, err = packfile.FindOffset(f.Head)
+ c.Assert(err, IsNil)
+ size, err = packfile.GetSizeByOffset(offset)
+ c.Assert(err, IsNil)
+ c.Assert(size, Equals, int64(245))
+}