Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to list all tags? #298

Closed
nkt opened this issue Nov 26, 2014 · 6 comments
Closed

How to list all tags? #298

nkt opened this issue Nov 26, 2014 · 6 comments

Comments

@nkt
Copy link
Contributor

nkt commented Nov 26, 2014

Hi!

var GitRepository = require('nodegit').Repository;
var GitTag = require('nodegit').Tag;
var Promise = require('bluebird');

var tags = GitRepository.open(repositoryPath).then(function (repo) {
    GitTag.list(repo);
});
Promise.map(tags, function (tag) {
    return {
        name: tag.name()
    }
}).then(function (tags) {
    res.json(tags);
});

This code throws error: Repository repo is required..

@nkt
Copy link
Contributor Author

nkt commented Nov 26, 2014

Also Repository::getTagByName throws The requested type does not match the type in the ODB

@johnhaley81
Copy link
Collaborator

This is a bug. The generated code didn't correctly figure out the return value of that C function so I'll start a fix for that.

Once that's fixed though your code will need some modifications though to work correctly.

var NodeGit = require("nodegit");
var repo;

var tags = NodeGit.Repository.open(repositoryPath).then(function (repoResult) {
    repo = repoResult;
    return NodeGit.Tag.list(repo);
});

// tags is already the list of names since NodeGit.Tag.list will return an array of strings containing
// each annotated tag's name

// Now to get the list of non-annotated tags you'll have to make another call to get them
repo.getReferenceNames(NodeGit.Reference.TYPE.OID)
.then(function (refs) {
    refs.forEach(function(ref) {
        if (ref.isTag()) {
            tags.push(ref.name());
        }
    });
}).then(function () {
    res.json(tags);
});

This is weird because tags are treated completely different in libgit2 depending on whether or not they are annotated. Which is exactly why you are getting that The requested type does not match the type in the ODB.

A non-annotated tag is returning the OID for the commit it's pointing to so you're telling the system to get a tag but asking for a commit instead. So you can only use getTagByName for an annotated tag.

It's weird, I know. I'm working on making it better right now :)

@johnhaley81
Copy link
Collaborator

The PR #300 should fix that but. And PR #297 should help with the weirdness between non-annotated tags and tags

@dickeylth
Copy link

It seems that there's an error in the code above:

repo.getReferenceNames(NodeGit.Reference.TYPE.OID) should be repo.getReferences(NodeGit.Reference.TYPE.OID).

@gausie
Copy link

gausie commented Aug 12, 2015

I'm getting the ODB error for non-annotated tags still (version 0.4.1)

@larboyer
Copy link

This is working nicely for me:

var nodegit = require("nodegit");

function getVersionArray(repo_root, callback) {
    nodegit.Repository.open(repo_root).then( function( repo_handle ) {
        return nodegit.Tag.list(repo_handle);
    })
    .then( function(tag_list) {
        callback(null, tag_list);
    }) 
}

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

No branches or pull requests

5 participants