FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #887 from dkoontz/revert-tests · nodegit/nodegit@e63536f · GitHub

Repository navigation

Commit e63536f

Browse files
committed
Merge pull request #887 from dkoontz/revert-tests
Tests for Revert.revert
2 parents 87da8bf + 3056d53 commit e63536f

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

‎generate/input/descriptor.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,20 @@
17951795
},
17961796
"revert": {
17971797
"functions": {
1798+
"git_revert": {
1799+
"isAsync": true,
1800+
"return": {
1801+
"isErrorCode": true
1802+
}
1803+
},
1804+
"git_revert_commit": {
1805+
"isAsync": true,
1806+
"args": {
1807+
"merge_options": {
1808+
"isOptional": true
1809+
}
1810+
}
1811+
},
17981812
"git_revert_init_options": {
17991813
"ignore": true
18001814
}

‎lib/revert.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var NodeGit = require("../");
2+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
3+
4+
var Revert = NodeGit.Revert;
5+
6+
/**
7+
* Reverts the given commit against the given "our" commit, producing an index
8+
* that reflects the result of the revert.
9+
*
10+
* @async
11+
* @param {Repository} repo the repository that contains the given commits.
12+
* @param {Commit} revert_commit the commit to revert
13+
* @param {Commit} our_commit the commit to revert against (e.g. HEAD)
14+
* @param {Number} mainline the parent of the revert commit, if it is a merge
15+
* @param {MergeOptions} merge_options the merge options (or null for defaults)
16+
*
17+
* @return {Index} the index result
18+
*/
19+
var commit = Revert.commit;
20+
Revert.commit = function(
21+
repo,
22+
revert_commit,
23+
our_commit,
24+
mainline,
25+
merge_options,
26+
callback
27+
) {
28+
merge_options = normalizeOptions(merge_options, NodeGit.MergeOptions);
29+
30+
return commit.call(
31+
this,
32+
repo,
33+
revert_commit,
34+
our_commit,
35+
mainline,
36+
merge_options
37+
)
38+
.then(function(result) {
39+
if (typeof callback === "function") {
40+
callback(null, result);
41+
}
42+
43+
return result;
44+
}, callback);
45+
};
46+
47+
module.exports = Revert;

‎test/tests/revert.js‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var _ = require("lodash");
2+
var assert = require("assert");
3+
var RepoUtils = require("../utils/repository_setup");
4+
var path = require("path");
5+
var fs = require("fs");
6+
var local = path.join.bind(path, __dirname);
7+
8+
describe("Revert", function() {
9+
var NodeGit = require("../../");
10+
11+
var Revert = NodeGit.Revert;
12+
var RevertOptions = NodeGit.RevertOptions;
13+
14+
var test;
15+
var fileName = "foobar.js";
16+
var repoPath = local("../repos/revertRepo");
17+
18+
beforeEach(function() {
19+
test = this;
20+
21+
return RepoUtils.createRepository(repoPath)
22+
.then(function(repository) {
23+
test.repository = repository;
24+
25+
return RepoUtils.commitFileToRepo(
26+
repository,
27+
fileName,
28+
"line1\nline2\nline3"
29+
);
30+
})
31+
.then(function(firstCommit) {
32+
test.firstCommit = firstCommit;
33+
});
34+
});
35+
36+
it("revert modifies the working directoy", function() {
37+
var fileStats = fs.statSync(path.join(repoPath, fileName));
38+
assert.ok(fileStats.isFile());
39+
40+
Revert.revert(test.repository, test.firstCommit, new RevertOptions())
41+
.then(function() {
42+
try {
43+
fs.statSync(path.join(repoPath, fileName));
44+
assert.fail("Working directory was not reverted");
45+
}
46+
catch (error) {
47+
// pass
48+
}
49+
});
50+
});
51+
52+
it("revert modifies the index", function() {
53+
Revert.revert(test.repository, test.firstCommit, new RevertOptions())
54+
.then(function() {
55+
return test.repository.index();
56+
})
57+
.then(function(index) {
58+
var entries = index.entries;
59+
assert.equal(1, entries.length);
60+
assert.ok(_.endsWith(fileName, entries[0].path));
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL