~kornellapacz/gmnigit

279d605b0769c48612e55c5a174f8d68b628fbc7 — Omar Polo 2 years ago b71d600
handle annotated tags too

Git has two types of pointers: annotated and lightweight ones.  gmnigit
was only handling lightweight ones (they are bare pointers to commits,
just like git branches).  This improve the tag support to handle
annotated tags too, which are pointers to full git objects with various
information, among which a pointer to the commit.
1 files changed, 18 insertions(+), 3 deletions(-)

M commits.go
M commits.go => commits.go +18 -3
@@ 86,15 86,30 @@ func createRefsFile(r *git.Repository) {
	iter, err := r.Tags()
	check(err)
	err = iter.ForEach(func(ref *plumbing.Reference) error {
		c, err := r.CommitObject(ref.Hash())
		if err != nil {
		var c *object.Commit

		hash := ref.Hash()
		obj, err := r.TagObject(hash)
		switch err {
		case nil:
			// an annotated tag
			if c, err = r.CommitObject(obj.Target); err != nil {
				return err
			}
			hash = obj.Target
		case plumbing.ErrObjectNotFound:
			// a lightweight tag
			if c, err = r.CommitObject(hash); err != nil {
				return err
			}
		default:
			return err
		}

		tag := fmt.Sprintf(
			"=> ../%s/%s.patch %s - %s",
			commitsSubPath,
			ref.Hash(),
			hash,
			c.Author.When.Format("2006-01-02"),
			filepath.Base(ref.Name().String()),
		)