So there are a few things you're missing with your code. First one is that you aren't terminating the promise chain so errors are being swallowed. You'll want to end it with either a .catch
or a .done
.
Second, I think you're not quite sure what a checkout does. One of the confusing things with low-level git and how it differs from git CLI is that Checkout only updates your working directory to reflect the tree pointed to by the second parameter.
Third, you're passing in a string to a method that is expecting something else. The docs are showing that it's looking for an Oid, Tree, Commit, or Reference. Let's spruce up that code a bit.
var NodeGit = require("nodegit");
var open = NodeGit.Repository.open;
var Tag = NodeGit.Tag;
var Checkout = NodeGit.Checkout;
open(location).then(function (repo) {
return Tag.list(repo)
.then(function(array) {
// array is ['v1.0.0','v2.0.0']
return Tag.lookup(repo,array[0]);
})
.then(function(tag) {
return Checkout.tree(repo, tag.targetId(), { checkoutStrategy: Checkout.STRATEGY.SAFE_CREATE})
.then(function() {
repo.setHeadDetached(tag.targetId(), repo.defaultSignature, "Checkout: HEAD " + tag.targetId());
});
});
})
.catch(function(error) {
// log error
});
That should point you in the right direction. If you need more help I would recommend stopping by our gitter channel where we are pretty active.