src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.9k stars 540 forks source link

git-describe #736

Open fenollp opened 6 years ago

fenollp commented 6 years ago

I see in COMPATIBILITY.md that describe is neither supported nor unsupported (empty box). I also see that there are no implementation containing that name.

  1. If it is implemented, could you point me to the right function?
  2. If not, any plans on supporting it?

I am looking for the equivalent of git describe --abbrev --dirty --always --tags.

Maybe related: https://github.com/src-d/go-git/issues/599 https://github.com/src-d/go-git/pull/139 Keep up the amazing work!

edupo commented 6 years ago

This feature will be helpful for us so I started writing something.

My idea was to get the log of the HEAD and check each commit against the tag pool until a match... But I see some issue with the tag check:

From here is not hard to create a proto describe using the tag, the number of new commits from the tag and the hash of the head...

edupo commented 6 years ago

Here is my basic implementation of a git describe with the idea of a map and a wrapper struct for go-git.

https://github.com/edupo/semver-cli/blob/master/gitWrapper/git.go

I'm not an expert on the matter but if this solution works for others I may do a PR on the go-git. (If I ever understand the million details required to contribute... xD)

mcuadros commented 6 years ago

PRs are more than welcome.