Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,18 @@
"ignore": true
},
"git_checkout_tree": {
"ignore": true
"args": {
"treeish": {
"isOptional": true
},
"opts": {
"isOptional": true
}
},
"isAsync": true,
"return": {
"isErrorCode": true
}
}
}
},
Expand Down
15 changes: 14 additions & 1 deletion lib/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ var normalizeOptions = require("./util/normalize_options");

var Checkout = NodeGit.Checkout;
var head = Checkout.head;
var tree = Checkout.tree;

/**
* Patch head checkout to automatically coerce objects.
*
* @param repo
* @param url
* @param options
*/
Checkout.head = function(url, options) {
Expand All @@ -16,5 +17,17 @@ Checkout.head = function(url, options) {
return head.call(this, url, options);
};

/**
* Patch tree checkout to automatically coerce objects.
*
* @param repo
* @param treeish
* @param options
*/
Checkout.tree = function(repo, treeish, options) {
options = normalizeOptions(options, NodeGit.CheckoutOptions);

return tree.call(this, repo, treeish, options);
};

module.exports = Checkout;
12 changes: 12 additions & 0 deletions test/tests/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,16 @@ describe("Checkout", function() {
assert.ok(~packageJson.indexOf("\"ejs\": \"~1.0.0\","));
});
});

it("can checkout by tree", function() {
var test = this;

return test.repo.getTagByName("annotated-tag").then(function(tag) {
return Checkout.tree(test.repo, test.tag);
}).then(function() {
return test.repo.getHeadCommit();
}).then(function(commit) {
assert.equal(commit, "32789a79e71fbc9e04d3eff7425e1771eb595150");
});
});
});