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
3 changes: 0 additions & 3 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,9 +1182,6 @@
"functions": {
"git_pathspec_match_list_free": {
"ignore": true
},
"git_pathspec_new": {
"ignore": true
}
}
},
Expand Down
27 changes: 26 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var NodeGit = require("../");

var Index = NodeGit.Index;
var Status = NodeGit.Status;
var Pathspec = NodeGit.Pathspec;

/**
* Return an array of the entries in this index.
Expand All @@ -19,7 +21,30 @@ Index.prototype.entries = function() {

var addAll = Index.prototype.addAll;
Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
return addAll.call(this, pathspec || "*", flags, matchedCallback, null);
// This status path code is here to speedup addall, which currently is
// excessively slow due to adding every single unignored file to the index
// even if it has no changes. Remove this when it's fixed in libgit2
// https://github.com/libgit2/libgit2/issues/2687
var paths = [];
var repo = this.owner();
var statusCB = function(path) {
paths.push(path);
};
var idx = this;
return Pathspec.create(pathspec || "*")
.then(function(ps) {
pathspec = ps;
return Status.foreach(repo, statusCB);
})
.then(function() {
return paths;
})
.then(function(paths) {
paths = paths.filter(function(path) {
return !!(pathspec.matchesPath(0, path));
});
return addAll.call(idx, paths, flags, matchedCallback, null);
});
};

var removeAll = Index.prototype.removeAll;
Expand Down
50 changes: 50 additions & 0 deletions test/tests/pathspec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var assert = require("assert");

describe("Pathspec", function() {
var NodeGit = require("../../");
var Pathspec = NodeGit.Pathspec;

it("can accept just about anything against a * pathspec", function() {
return Pathspec.create("*")
.then(function(pathspec) {
assert.equal(pathspec.matchesPath(0, "burritoooo"), 1);
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 1);
});
});

it("can take a * in an array", function() {
return Pathspec.create(["*"])
.then(function(pathspec) {
assert.equal(pathspec.matchesPath(0, "burritoooo"), 1);
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 1);
});
});

it("can take a single file", function() {
return Pathspec.create(["myDir/burritoSupreme.mp4"])
.then(function(pathspec) {
assert.equal(pathspec.matchesPath(0, "myDir/burritoSupreme.mp4"), 1);
assert.equal(pathspec.matchesPath(0, "bob/ted/yoghurt.mp3"), 0);
});
});

it("can take files in an array", function() {
return Pathspec.create(["gwendoline.txt", "sausolito.ogg"])
.then(function(pathspec) {
assert.equal(pathspec.matchesPath(0, "gwendoline.txt"), 1);
assert.equal(pathspec.matchesPath(0, "sausolito.ogg"), 1);
assert.equal(pathspec.matchesPath(0, "sausolito.txt"), 0);
});
});

it("can handle dirs", function() {
return Pathspec.create(["myDir/", "bob.js"])
.then(function(pathspec) {
assert.equal(pathspec.matchesPath(0, "bob.js"), 1);
assert.equal(pathspec.matchesPath(0, "myDir/bob2.js"), 1);
assert.equal(pathspec.matchesPath(0, "bob2.js"), 0);
assert.equal(pathspec.matchesPath(0, "herDir/bob.js"), 0);
});
});

});