Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@
],
"functions": {
"git_status_byindex": {
"ignore": true
"isAsync": false
},
"git_status_foreach": {
"isAsync": true,
Expand All @@ -1575,7 +1575,7 @@
"status_list": {
"functions": {
"git_status_list_new": {
"isAsync": false,
"isAsync": true,
"args": {
"opts": {
"isOptional": true
Expand Down
19 changes: 19 additions & 0 deletions generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@
]
}
],
[
"git_status_entry",
{
"fields": [
{
"type": "git_status_t",
"name": "status"
},
{
"type": "git_diff_delta *",
"name": "head_to_index"
},
{
"type": "git_diff_delta *",
"name": "index_to_workdir"
}
]
}
],
[
"git_diff_perfdata",
{
Expand Down
15 changes: 13 additions & 2 deletions generate/templates/partials/fields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@
{% if field | isFixedLengthString %}
char* {{ field.name }} = (char *)ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue()->{{ field.name }};
{% else %}
{{ field.cType }} {% if not field.cppClassName|isV8Value %}*{% endif %}{{ field.name }} =
{% if not field.cppClassName|isV8Value %}&{% endif %}ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue()->{{ field.name }};
{{ field.cType }}
{% if not field.cppClassName|isV8Value %}
{% if not field.cType|isPointer %}
*
{% endif %}
{% endif %}
{{ field.name }} =
{% if not field.cppClassName|isV8Value %}
{% if not field.cType|isPointer %}
&
{% endif %}
{% endif %}
ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue()->{{ field.name }};
{% endif %}

{% partial convertToV8 field %}
Expand Down
37 changes: 34 additions & 3 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Promise = require("nodegit-promise");
var normalizeOptions = require("./util/normalize_options");
var Status = require("./status");
var StatusFile = require("./status_file");
var StatusList = require("./status_list");

var TreeBuilder = NodeGit.Treebuilder;
var Repository = NodeGit.Repository;
Expand Down Expand Up @@ -727,17 +728,17 @@ Repository.initExt = function(repo_path, opts) {
* Get the status of a repo to it's working directory
*
* @param {obj} opts
* @return {Object} Promise object.
* @return {Array<StatusFile>}
*/
Repository.prototype.getStatus = function(opts) {
var statuses = [];
var statusCallback = function(path, status) {
statuses.push(new StatusFile(path, status));
statuses.push(new StatusFile({path: path, status: status}));
};

if (!opts) {
opts = {
flags: Status.OPT.INCLUDE_UNTRACKED +
flags: Status.OPT.INCLUDE_UNTRACKED |
Status.OPT.RECURSE_UNTRACKED_DIRS
};
}
Expand All @@ -747,4 +748,34 @@ Repository.prototype.getStatus = function(opts) {
});
};

/**
* Get extended statuses of a repo to it's working directory. Status entries
* have `status`, `headToIndex` delta, and `indexToWorkdir` deltas
*
* @param {obj} opts
* @return {Array<StatusEntry>}
*/
Repository.prototype.getStatusExt = function(opts) {
var statuses = [];

if (!opts) {
opts = {
flags: Status.OPT.INCLUDE_UNTRACKED |
Status.OPT.RECURSE_UNTRACKED_DIRS |
Status.OPT.RENAMES_INDEX_TO_WORKDIR |
Status.OPT.RENAMES_HEAD_TO_INDEX |
Status.OPT.RENAMES_FROM_REWRITES
};
}

return StatusList.create(this, opts).then(function(list) {
for (var i = 0; i < list.entrycount(); i++) {
var entry = Status.byIndex(list, i);
statuses.push(new StatusFile({entry: entry}));
}

return statuses;
});
};

module.exports = Repository;
29 changes: 28 additions & 1 deletion lib/status_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ var NodeGit = require("../");

var Status = NodeGit.Status;

var StatusFile = function(path, status) {
var StatusFile = function(args) {
var path = args.path;
var status = args.status;
var entry = args.entry;

if (entry) {
status = entry.status();
if (entry.indexToWorkdir()) {
path = entry.indexToWorkdir().newFile().path();
} else {
path = entry.headToIndex().newFile().path();
}
}

var codes = Status.STATUS;

Expand All @@ -20,6 +32,7 @@ var StatusFile = function(path, status) {

var data = {
path: path,
entry: entry,
statusBit: status,
statuses: getStatus()
};
Expand All @@ -31,6 +44,20 @@ var StatusFile = function(path, status) {
statusBit: function() {
return data.statusBit;
},
headToIndex: function() {
if (data.entry) {
return entry.headToIndex();
} else {
return undefined;
}
},
indexToWorkdir: function() {
if (data.entry) {
return entry.indexToWorkdir();
} else {
return undefined;
}
},
path: function() {
return data.path;
},
Expand Down
13 changes: 13 additions & 0 deletions lib/status_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var NodeGit = require("../");
var normalizeOptions = require("./util/normalize_options");

var StatusList = NodeGit.StatusList;

// Override StatusList.create to normalize opts
var create = StatusList.create;
StatusList.create = function(repo, opts) {
opts = normalizeOptions(opts, NodeGit.StatusOptions);
return create(repo, opts);
};

module.exports = StatusList;
26 changes: 26 additions & 0 deletions test/tests/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,30 @@ describe("Repository", function() {
});
});
});

it("gets extended statuses", function() {
var fileName = "my-new-file-that-shouldnt-exist.file";
var fileContent = "new file from repository test";
var repo = this.repository;
var filePath = path.join(repo.workdir(), fileName);

return fse.writeFile(filePath, fileContent)
.then(function() {
return repo.getStatusExt().then(function(statuses) {
assert.equal(statuses.length, 1);
assert.equal(statuses[0].path(), fileName);
assert.equal(statuses[0].indexToWorkdir().newFile().path(), fileName);
assert.ok(statuses[0].isNew());
});
})
.then(function() {
return fse.remove(filePath);
})
.catch(function (e) {
return fse.remove(filePath)
.then(function() {
return Promise.reject(e);
});
});
});
});
2 changes: 1 addition & 1 deletion test/tests/status_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("StatusFile", function() {
var statusCode = Status.STATUS.WT_NEW;

before(function() {
this.status = new StatusFile(pathName, statusCode);
this.status = new StatusFile({path: pathName, status: statusCode});
});

it("passes the path to the working function", function() {
Expand Down
62 changes: 62 additions & 0 deletions test/tests/status_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 Status = require(local("../../lib/status"));
var StatusList = require(local("../../lib/status_list"));
var Repository = require(local("../../lib/repository"));

var reposPath = local("../repos/workdir/.git");

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: local("../repos/workdir")})
.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);
});

});
});
});