Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 9cc654c

Browse files
committed
git: Add some tests for annotated tag deletion
Added a couple of tests for annotated tag deletion: * The first one is a general test and should work regardless of the fixture used - the tag object could possibly be packed, so we do a prune *and* a repack operation before testing to see if the object was GCed correctly. * The second one actually creates the tag to be deleted, so that the tag object gets created as a loose, unpacked object. This is so we can effectively test that purning unpacked objects is now working 100% correctly (this was failing before because tag objects were not supported for walking). Signed-off-by: Chris Marchesi <chrism@vancluevertech.com>
1 parent b19b3b8 commit 9cc654c

File tree

1 file changed

+110
-3
lines changed

1 file changed

+110
-3
lines changed

repository_test.go

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,113 @@ func (s *RepositorySuite) TestDeleteTagMissingTag(c *C) {
15601560
c.Assert(err, Equals, ErrTagNotFound)
15611561
}
15621562

1563+
func (s *RepositorySuite) TestDeleteTagAnnotated(c *C) {
1564+
url := s.GetLocalRepositoryURL(
1565+
fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),
1566+
)
1567+
1568+
dir, err := ioutil.TempDir("", "go-git-test-deletetag-annotated")
1569+
c.Assert(err, IsNil)
1570+
1571+
defer os.RemoveAll(dir) // clean up
1572+
1573+
fss, err := filesystem.NewStorage(osfs.New(dir))
1574+
c.Assert(err, IsNil)
1575+
1576+
r, _ := Init(fss, nil)
1577+
err = r.clone(context.Background(), &CloneOptions{URL: url})
1578+
c.Assert(err, IsNil)
1579+
1580+
ref, err := r.Tag("annotated-tag")
1581+
c.Assert(ref, NotNil)
1582+
c.Assert(err, IsNil)
1583+
1584+
obj, err := r.TagObject(ref.Hash())
1585+
c.Assert(obj, NotNil)
1586+
c.Assert(err, IsNil)
1587+
1588+
err = r.DeleteTag("annotated-tag")
1589+
c.Assert(err, IsNil)
1590+
1591+
_, err = r.Tag("annotated-tag")
1592+
c.Assert(err, Equals, ErrTagNotFound)
1593+
1594+
// Run a prune (and repack, to ensure that we are GCing everything regardless
1595+
// of the fixture in use) and try to get the tag object again.
1596+
//
1597+
// The repo needs to be re-opened after the repack.
1598+
err = r.Prune(PruneOptions{Handler: r.DeleteObject})
1599+
c.Assert(err, IsNil)
1600+
1601+
err = r.RepackObjects(&RepackConfig{})
1602+
c.Assert(err, IsNil)
1603+
1604+
r, err = PlainOpen(dir)
1605+
c.Assert(r, NotNil)
1606+
c.Assert(err, IsNil)
1607+
1608+
// Now check to see if the GC was effective in removing the tag object.
1609+
obj, err = r.TagObject(ref.Hash())
1610+
c.Assert(obj, IsNil)
1611+
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
1612+
}
1613+
1614+
func (s *RepositorySuite) TestDeleteTagAnnotatedUnpacked(c *C) {
1615+
url := s.GetLocalRepositoryURL(
1616+
fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),
1617+
)
1618+
1619+
dir, err := ioutil.TempDir("", "go-git-test-deletetag-annotated-unpacked")
1620+
c.Assert(err, IsNil)
1621+
1622+
defer os.RemoveAll(dir) // clean up
1623+
1624+
fss, err := filesystem.NewStorage(osfs.New(dir))
1625+
c.Assert(err, IsNil)
1626+
1627+
r, _ := Init(fss, nil)
1628+
err = r.clone(context.Background(), &CloneOptions{URL: url})
1629+
c.Assert(err, IsNil)
1630+
1631+
// Create a tag for the deletion test. This ensures that the ultimate loose
1632+
// object will be unpacked (as we aren't doing anything that should pack it),
1633+
// so that we can effectively test that a prune deletes it, without having to
1634+
// resort to a repack.
1635+
h, err := r.Head()
1636+
c.Assert(err, IsNil)
1637+
1638+
expectedHash := h.Hash()
1639+
1640+
ref, err := r.CreateTag("foobar", expectedHash, &TagObjectOptions{
1641+
Tagger: defaultSignature(),
1642+
Message: "foo bar baz qux",
1643+
})
1644+
c.Assert(err, IsNil)
1645+
1646+
tag, err := r.Tag("foobar")
1647+
c.Assert(err, IsNil)
1648+
1649+
obj, err := r.TagObject(tag.Hash())
1650+
c.Assert(obj, NotNil)
1651+
c.Assert(err, IsNil)
1652+
1653+
err = r.DeleteTag("foobar")
1654+
c.Assert(err, IsNil)
1655+
1656+
_, err = r.Tag("foobar")
1657+
c.Assert(err, Equals, ErrTagNotFound)
1658+
1659+
// As mentioned, only run a prune. We are not testing for packed objects
1660+
// here.
1661+
err = r.Prune(PruneOptions{Handler: r.DeleteObject})
1662+
c.Assert(err, IsNil)
1663+
1664+
// Now check to see if the GC was effective in removing the tag object.
1665+
obj, err = r.TagObject(ref.Hash())
1666+
c.Assert(obj, IsNil)
1667+
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
1668+
}
1669+
15631670
func (s *RepositorySuite) TestBranches(c *C) {
15641671
f := fixtures.ByURL("https://github.com/git-fixtures/root-references.git").One()
15651672
sto, err := filesystem.NewStorage(f.DotGit())
@@ -1833,9 +1940,9 @@ func (s *RepositorySuite) TestResolveRevisionWithErrors(c *C) {
18331940
c.Assert(err, IsNil)
18341941

18351942
datas := map[string]string{
1836-
"efs/heads/master~": "reference not found",
1837-
"HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`,
1838-
"HEAD^{/whatever}": `No commit message match regexp : "whatever"`,
1943+
"efs/heads/master~": "reference not found",
1944+
"HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`,
1945+
"HEAD^{/whatever}": `No commit message match regexp : "whatever"`,
18391946
"4e1243bd22c66e76c2ba9eddc1f91394e57f9f83": "reference not found",
18401947
"918c48b83bd081e863dbe1b80f8998f058cd8294": `refname "918c48b83bd081e863dbe1b80f8998f058cd8294" is ambiguous`,
18411948
}

0 commit comments

Comments
 (0)