Skip to content

Commit 08d619e

Browse files
committed
Adds in git_checkout_tree
1 parent b4e85cd commit 08d619e

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

generate/input/descriptor.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,18 @@
199199
"ignore": true
200200
},
201201
"git_checkout_tree": {
202-
"ignore": true
202+
"args": {
203+
"treeish": {
204+
"isOptional": true
205+
},
206+
"opts": {
207+
"isOptional": true
208+
}
209+
},
210+
"isAsync": true,
211+
"return": {
212+
"isErrorCode": true
213+
}
203214
}
204215
}
205216
},

lib/checkout.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ var normalizeOptions = require("./util/normalize_options");
33

44
var Checkout = NodeGit.Checkout;
55
var head = Checkout.head;
6+
var tree = Checkout.tree;
67

78
/**
89
* Patch head checkout to automatically coerce objects.
910
*
10-
* @param repo
11+
* @param url
1112
* @param options
1213
*/
1314
Checkout.head = function(url, options) {
@@ -16,5 +17,17 @@ Checkout.head = function(url, options) {
1617
return head.call(this, url, options);
1718
};
1819

20+
/**
21+
* Patch tree checkout to automatically coerce objects.
22+
*
23+
* @param repo
24+
* @param treeish
25+
* @param options
26+
*/
27+
Checkout.tree = function(repo, treeish, options) {
28+
options = normalizeOptions(options, NodeGit.CheckoutOptions);
29+
30+
return tree.call(this, repo, treeish, options);
31+
};
1932

2033
module.exports = Checkout;

test/tests/checkout.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@ describe("Checkout", function() {
3131
assert.ok(~packageJson.indexOf("\"ejs\": \"~1.0.0\","));
3232
});
3333
});
34+
35+
it("can checkout by tree", function() {
36+
var test = this;
37+
38+
return test.repo.getTagByName("annotated-tag").then(function(tag) {
39+
return Checkout.tree(test.repo, test.tag);
40+
}).then(function() {
41+
return test.repo.getHeadCommit();
42+
}).then(function(commit) {
43+
assert.equal(commit, "32789a79e71fbc9e04d3eff7425e1771eb595150");
44+
});
45+
});
3446
});

0 commit comments

Comments
 (0)