go-git
go-git copied to clipboard
How to know whether a tag is a lightweight tag or an annotated one
I've know that go-git supported creating an annotated tag from issue#430.
But I couldnot find a way to get:
- Whether a tag is an annotated tag or a lightweight tag
-
Commit message of a lightweight tag(I found a way and listed it below. If there is any better ways please let me know) - Commit message of an annotated tag
What I've tried:
tagrefs, _ := repo.Tags()
tagrefs.ForEach(func(t *plumbing.Reference) error {
// Here t contains Name(), Hash(), Type() ...
fmt.Println(t)
return nil
})
Actually, git cat-file -t <tagname> and git tag -n is somewhat similar to what I need.
Thanks for your replying.
I found the following way to get commit message of lightweight tags.
tagrefs, _ := repo.Tags()
tagrefs.ForEach(func(t *plumbing.Reference) error {
h, err := repo.ResolveRevision(plumbing.Revision(t.Hash().String()))
checkError(err)
if h == nil {
fmt.Println("empty return")
return nil
}
obj, err := repo.Object(plumbing.AnyObject, *h)
checkError(err)
o := obj.(*object.Commit)
fmt.Println(o.Message)
return nil
})