diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 71d0deb78..e47b32910 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -199,7 +199,18 @@ "ignore": true }, "git_checkout_tree": { - "ignore": true + "args": { + "treeish": { + "isOptional": true + }, + "opts": { + "isOptional": true + } + }, + "isAsync": true, + "return": { + "isErrorCode": true + } } } }, diff --git a/lib/checkout.js b/lib/checkout.js index aefd09b08..aa07b385b 100644 --- a/lib/checkout.js +++ b/lib/checkout.js @@ -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) { @@ -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; diff --git a/test/tests/checkout.js b/test/tests/checkout.js index b38cde196..73acb1daa 100644 --- a/test/tests/checkout.js +++ b/test/tests/checkout.js @@ -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"); + }); + }); });