Skip to content

Commit 5afb809

Browse files
committed
actually use pathspecs. enable pathspec.create
1 parent a8fd045 commit 5afb809

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

generate/input/descriptor.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,6 @@
11821182
"functions": {
11831183
"git_pathspec_match_list_free": {
11841184
"ignore": true
1185-
},
1186-
"git_pathspec_new": {
1187-
"ignore": true
11881185
}
11891186
}
11901187
},

lib/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var NodeGit = require("../");
22

33
var Index = NodeGit.Index;
44
var Status = NodeGit.Status;
5+
var Pathspec = NodeGit.Pathspec;
56
var Promise = require("nodegit-promise");
67
/**
78
* Return an array of the entries in this index.
@@ -25,15 +26,24 @@ Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
2526
// even if it has no changes. Remove this when it's fixed in libgit2
2627
// https://github.com/libgit2/libgit2/issues/2687
2728
var paths = [];
29+
var repo = this.owner();
2830
var statusCB = function(path) {
2931
paths.push(path);
3032
};
31-
return Status.foreach(this.owner(), statusCB)
33+
var idx = this;
34+
return Pathspec.create(pathspec || "*")
35+
.then(function(ps) {
36+
pathspec = ps;
37+
return Status.foreach(repo, statusCB);
38+
})
3239
.then(function() {
3340
return Promise.resolve(paths);
3441
})
3542
.then(function(paths) {
36-
return addAll.call(this, pathspec || "*", flags, matchedCallback, null);
43+
paths = paths.filter(function(path) {
44+
return !!(pathspec.matchesPath(0, path));
45+
});
46+
return addAll.call(idx, paths, flags, matchedCallback, null);
3747
});
3848
};
3949

0 commit comments

Comments
 (0)