Skip to content

Commit aa88424

Browse files
committed
Begin implementing status by index and StatusEntry
1 parent f0b29f5 commit aa88424

4 files changed

Lines changed: 93 additions & 1 deletion

File tree

generate/input/descriptor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@
15531553
],
15541554
"functions": {
15551555
"git_status_byindex": {
1556-
"ignore": true
1556+
"isAsync": false
15571557
},
15581558
"git_status_foreach": {
15591559
"isAsync": true,

generate/input/libgit2-supplement.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@
187187
]
188188
}
189189
],
190+
[
191+
"git_status_entry",
192+
{
193+
"fields": [
194+
{
195+
"type": "git_status_t",
196+
"name": "status"
197+
},
198+
{
199+
"type": "git_diff_delta *",
200+
"name": "head_to_index"
201+
},
202+
{
203+
"type": "git_diff_delta *",
204+
"name": "index_to_workdir"
205+
}
206+
]
207+
}
208+
],
190209
[
191210
"git_diff_perfdata",
192211
{

lib/status_list.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var NodeGit = require("../");
2+
var normalizeOptions = require("./util/normalize_options");
3+
4+
var StatusList = NodeGit.StatusList;
5+
6+
// Override StatusList.create to normalize opts
7+
var create = StatusList.create;
8+
StatusList.create = function(repo, opts) {
9+
opts = normalizeOptions(opts, NodeGit.StatusOptions);
10+
return create(repo, opts);
11+
};
12+
13+
module.exports = StatusList;

test/tests/status_list.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
var promisify = require("promisify-node");
4+
var Promise = require("nodegit-promise");
5+
var fse = promisify(require("fs-extra"));
6+
var local = path.join.bind(path, __dirname);
7+
var exec = promisify(function(command, opts, callback) {
8+
return require("child_process").exec(command, opts, callback);
9+
});
10+
11+
describe.only("StatusList", function() {
12+
var Status = require(local("../../lib/status"));
13+
var StatusList = require(local("../../lib/status_list"));
14+
var Repository = require(local("../../lib/repository"));
15+
16+
var reposPath = local("../repos/workdir/.git");
17+
18+
before(function() {
19+
var test = this;
20+
return Repository.open(reposPath)
21+
.then(function(repository) {
22+
test.repository = repository;
23+
});
24+
});
25+
26+
it("gets status with deltas", function() {
27+
var fileName = "my-new-file-that-shouldnt-exist.file";
28+
var fileContent = "new file from status tests";
29+
var repo = this.repository;
30+
var filePath = path.join(repo.workdir(), fileName);
31+
return exec("git clean -xdf", {cwd: local("../repos/workdir")})
32+
.then(function() {
33+
return fse.writeFile(filePath, fileContent);
34+
})
35+
.then(function() {
36+
var opts = {
37+
flags: Status.OPT.INCLUDE_UNTRACKED +
38+
Status.OPT.RECURSE_UNTRACKED_DIRS
39+
};
40+
41+
var list = StatusList.create(repo, opts);
42+
assert.equal(list.entrycount(), 1);
43+
44+
for (var i = 0; i < list.entrycount(); i++) {
45+
var entry = Status.byIndex(list, i);
46+
assert.equal(entry.indexToWorkdir().newFile().path(), fileName);
47+
}
48+
})
49+
.then(function() {
50+
return fse.remove(filePath);
51+
})
52+
.catch(function(e) {
53+
return fse.remove(filePath)
54+
.then(function() {
55+
return Promise.reject(e);
56+
});
57+
58+
});
59+
});
60+
});

0 commit comments

Comments
 (0)