forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_list.js
More file actions
63 lines (56 loc) · 1.81 KB
/
status_list.js
File metadata and controls
63 lines (56 loc) · 1.81 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
var assert = require("assert");
var path = require("path");
var promisify = require("promisify-node");
var Promise = require("nodegit-promise");
var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);
var exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});
describe("StatusList", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var Status = NodeGit.Status;
var StatusList = NodeGit.StatusList;
var reposPath = local("../repos/workdir");
before(function() {
var test = this;
return Repository.open(reposPath)
.then(function(repository) {
test.repository = repository;
});
});
it("gets status with deltas", function() {
var fileName = "my-new-file-that-shouldnt-exist.file";
var fileContent = "new file from status tests";
var repo = this.repository;
var filePath = path.join(repo.workdir(), fileName);
return exec("git clean -xdf", {cwd: reposPath})
.then(function() {
return fse.writeFile(filePath, fileContent);
})
.then(function() {
var opts = {
flags: Status.OPT.INCLUDE_UNTRACKED +
Status.OPT.RECURSE_UNTRACKED_DIRS
};
return StatusList.create(repo, opts);
})
.then(function(list) {
assert.equal(list.entrycount(), 1);
for (var i = 0; i < list.entrycount(); i++) {
var entry = Status.byIndex(list, i);
assert.equal(entry.indexToWorkdir().newFile().path(), fileName);
}
})
.then(function() {
return fse.remove(filePath);
})
.catch(function(e) {
return fse.remove(filePath)
.then(function() {
return Promise.reject(e);
});
});
});
});