Skip to content

Commit 2141be4

Browse files
author
John Haley
committed
Add git_reset_default and a test case
1 parent 5f60002 commit 2141be4

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

generate/input/descriptor.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,24 @@
14131413
}
14141414
}
14151415
},
1416+
"reset": {
1417+
"functions": {
1418+
"git_reset_default": {
1419+
"args": {
1420+
"target": {
1421+
"isOptional": true
1422+
},
1423+
"pathspecs": {
1424+
"isOptional": true
1425+
}
1426+
},
1427+
"isAsync": true,
1428+
"return": {
1429+
"isErrorCode": true
1430+
}
1431+
}
1432+
}
1433+
},
14161434
"revspec": {
14171435
"ignore": true
14181436
},

lib/reset.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var NodeGit = require("../");
2+
var normalizeOptions = require("./util/normalize_options");
3+
4+
var Reset = NodeGit.Reset;
5+
6+
var defaultFn = Reset.default;
7+
Reset.default = function(repo, target, pathspecs) {
8+
return defaultFn.call(this, repo, target, pathspecs);
9+
};
10+
11+
module.exports = Reset;

test/tests/reset.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
var local = path.join.bind(path, __dirname);
4+
5+
describe("Reset", function() {
6+
var Repository = require(local("../../lib/repository"));
7+
var Reset = require(local("../../lib/reset"));
8+
9+
var reposPath = local("../repos/workdir/.git");
10+
var currentCommitOid = "32789a79e71fbc9e04d3eff7425e1771eb595150";
11+
var previousCommitOid = "c82fb078a192ea221c9f1093c64321c60d64aa0d";
12+
var filePath = "package.json";
13+
14+
before(function() {
15+
var test = this;
16+
17+
return Repository.open(reposPath)
18+
.then(function(repository) {
19+
test.repo = repository;
20+
21+
return test.repo.getCommit(currentCommitOid);
22+
})
23+
.then(function(commit) {
24+
test.currentCommit = commit;
25+
26+
return commit.getEntry(filePath);
27+
})
28+
.then(function(entry) {
29+
return entry.getBlob();
30+
})
31+
.then(function(blob) {
32+
test.currentCommitBlob = blob;
33+
34+
return test.repo.getCommit(previousCommitOid);
35+
})
36+
.then(function(commit) {
37+
test.previousCommit = commit;
38+
39+
return commit.getEntry(filePath);
40+
})
41+
.then(function(entry) {
42+
return entry.getBlob();
43+
})
44+
.then(function(blob) {
45+
test.previousCommitBlob = blob;
46+
});
47+
});
48+
49+
it("can reset a file to a previous commit", function() {
50+
var test = this;
51+
52+
return Reset.default(test.repo, test.previousCommit, filePath)
53+
.then(function() {
54+
return test.repo.openIndex();
55+
})
56+
.then(function(index) {
57+
return index.writeTree();
58+
})
59+
.then(function(oid) {
60+
return test.repo.getTree(oid);
61+
})
62+
.then(function(tree) {
63+
return tree.getEntry(filePath);
64+
})
65+
.then(function(entry) {
66+
return entry.getBlob();
67+
})
68+
.then(function(blob) {
69+
var currentCommitContents = test.currentCommitBlob.toString();
70+
var previousCommitContents = test.previousCommitBlob.toString();
71+
var resetContents = blob.toString();
72+
73+
assert(resetContents != currentCommitContents);
74+
assert(resetContents == previousCommitContents);
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)