go-git / go-git

A highly extensible Git implementation in pure Go.
https://pkg.go.dev/github.com/go-git/go-git/v5
Apache License 2.0
5.85k stars 733 forks source link

How to get the Tag Name from a *object.Commit ID Hash (if one exists?) #551

Open gcstang opened 2 years ago

gcstang commented 2 years ago

For convenience we'll say the tag is v0.0.2 in this document

I can pull all tags using and loop through them tagrefs, err := repo.Tags()

looping using this provides a name for the plumbing.Reference Hash tagrefs.ForEach(func(t *plumbing.Reference) error { obj, err := repo.TagObject(t.Hash()) Here obj.Name == v0.0.2 and t.Hash() == 2cd76ba792107c08dd8156a96e3468b8304b6649

Now I need to loop commits and for a hash find if there's a tag name iter.ForEach(func(c *object.Commit) error {

If I print this c.ID().String() the value is 73dfadc751909a6053b91f5774a2b55c9f04cf44 it matches the value returned when I do this with the tag name I captured prior startHash, err := repo.ResolveRevision(plumbing.Revision("v0.0.2")) if I print startHash the value is 73dfadc751909a6053b91f5774a2b55c9f04cf44

However using the c.ID() in this doesn't provide a value even though it's the same printed hash obj, err := repo.TagObject(c.ID())

github-actions[bot] commented 1 month ago

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!