-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathrevert.js
More file actions
84 lines (71 loc) · 2.3 KB
/
revert.js
File metadata and controls
84 lines (71 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var _ = require("lodash");
var assert = require("assert");
var RepoUtils = require("../utils/repository_setup");
var path = require("path");
var fs = require("fs");
var local = path.join.bind(path, __dirname);
describe("Revert", function() {
var NodeGit = require("../../");
var Revert = NodeGit.Revert;
var RevertOptions = NodeGit.RevertOptions;
var Status = NodeGit.Status;
var test;
var fileName = "foobar.js";
var repoPath = local("../repos/revertRepo");
beforeEach(function() {
test = this;
return RepoUtils.createRepository(repoPath)
.then(function(repository) {
test.repository = repository;
return RepoUtils.commitFileToRepo(
repository,
fileName,
"line1\nline2\nline3"
);
})
.then(function(firstCommit) {
test.firstCommit = firstCommit;
});
});
it("revert modifies the working directoy", function() {
var fileStats = fs.statSync(path.join(repoPath, fileName));
assert.ok(fileStats.isFile());
return Revert.revert(test.repository, test.firstCommit, new RevertOptions())
.then(function() {
try {
fs.statSync(path.join(repoPath, fileName));
} catch (e) {
// we expect this not to exist
return;
}
assert.fail("Working directory was not reverted");
});
});
it("revert modifies the index", function() {
return Revert.revert(test.repository, test.firstCommit, new RevertOptions())
.then(() => test.repository.getStatus())
.then((status) => {
assert.equal(1, status.length);
assert.ok(_.endsWith(fileName, status[0].path()));
assert.equal(Status.STATUS.INDEX_DELETED, status[0].statusBit());
});
});
it("RevertOptions is optional (unspecified)", function() {
return Revert.revert(test.repository, test.firstCommit)
.catch(function(error) {
throw error;
});
});
it("RevertOptions is optional (null)", function() {
return Revert.revert(test.repository, test.firstCommit, null)
.catch(function(error) {
throw error;
});
});
it("RevertOptions without MergeOptions should not segfault", function() {
return Revert.revert(test.repository, test.firstCommit, {})
.catch(function(error) {
throw error;
});
});
});