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

How to know whether a tag is a lightweight tag or an annotated one #1211

Open
easonyq opened this issue Aug 19, 2019 · 1 comment
Open

How to know whether a tag is a lightweight tag or an annotated one #1211

easonyq opened this issue Aug 19, 2019 · 1 comment

Comments

@easonyq
Copy link

easonyq commented Aug 19, 2019

I've know that go-git supported creating an annotated tag from issue#430.

But I couldnot find a way to get:

  1. Whether a tag is an annotated tag or a lightweight tag
  2. Commit message of a lightweight tag (I found a way and listed it below. If there is any better ways please let me know)
  3. 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.

@easonyq easonyq changed the title How to get message of an annotated tag How to get commit message of a tag Aug 19, 2019
@easonyq easonyq changed the title How to get commit message of a tag How to know whether a tag is a lightweight tag or an annotated one Aug 19, 2019
@easonyq
Copy link
Author

easonyq commented Aug 19, 2019

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
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant